Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.1 Cannot resolve symbol 'R'

Android Studio 2.1, Java V8 Update 91, Gradle 2.1.0 .

I know that this questions has been asked many times here, but none of the recommendation solutions works out.

In a sudden after compiling ready to run on Emulator, my IDE give an error at the R.id attribute. Every Java files suddenly give the same error even I don't make any changes to the file.

I tried to make a new project, see if things different but the error keep coming. In my mind it could be internal error, again. Even I just update my IDE just now.

The Java file;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_science);

    list_View = (ListView) findViewById(R.id.maintable); 
    String[] Days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
    dayList.addAll(Arrays.asList(Days));
    adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dayList);
    list_View.setAdapter(adapter);

    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);

    if (nfc.isEnabled()) {
        adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dayList);
        Toast.makeText(this, "NFC turned ON", Toast.LENGTH_SHORT).show();
    }

    else {
        Toast.makeText(this, "Please turn On NFC", Toast.LENGTH_SHORT).show();
    }

}

The R is the error.

XML file that associate to the Java;

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/maintable"
    >
</ListView>

Is this, again, an internal error?

like image 546
Infinite Loops Avatar asked Dec 06 '22 18:12

Infinite Loops


1 Answers

Try syncing the project, go to Tools > Android > Sync Project with Gradle Files

UPDATE

If you're using Android Studio 3.3, use the Sync Project with Gradle Files icon

enter image description here

like image 121
Hadas Kaminsky Avatar answered Dec 09 '22 15:12

Hadas Kaminsky