简体   繁体   中英

MainActivity.java is not identifying any drawable or layout resource file

My android studio project was working fine until now but when I open it now, I am not able to access any of the layout or drawable resource files.

It suddenly says

error: cannot find symbol
        setContentView(R.layout.activity_main);

and the same for all the elements

This is happening only in MainActivity.java and not in any other file. This is what surprised me the most. I created a new layout resource file, a new java class with the same content but it still doesn't work

Well I seriously don't know where the problem is. If any of you know please help me

EDIT:

MainActivity.java:

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.speech.tts.TextToSpeech;
import android.speech.tts.Voice;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.sayatech.dictate.ui.GotoAdapter;
import com.theartofdev.edmodo.cropper.R;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.zip.GZIPInputStream;


public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_2);
        button = (Button) findViewById(R.id.BTN);
        ....

I had the same problem. All i did was updating Android Studio and fixed it.

I am finally able to access the layout resource files now and that's why I am answering my own question

I changed R.layout.activity_main to com.example.App.R.layout.activity_main and it worked!

Please let me know if there's a better method to do it. Or am I missing any imports?

Thank you all for your support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM