why does R does not exist error come in android?

31,025

Solution 1

Check if there are any errors in your resource files or any missing dependencies. Either of these will cause the R.java class to not be code-generated and thus a lot of errors like the ones you have shown.

Solution 2

In my case, this error occurred because I had changed the package name of the app (before publishing to Google Play, of course), but I forgot to update the package attribute of the manifest element in my AndroidManifest.xml file. Once the package attribute agreed with the new package name, the error went away.

Solution 3

Make sure you have: package 'YOUR PACKAGE NAME' in java file that calls R class

Solution 4

  1. Try Clean-> Build (If not just restart eclipse, it just worked!)
  2. In case you are importing project, make sure you choose proper Level.
Share:
31,025
garima
Author by

garima

I am yet another techie..learning everyday!!

Updated on March 20, 2020

Comments

  • garima
    garima over 4 years
    packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:196: package R does not exist
                      addPreferencesFromResource(R.xml.myfile);
                                                  ^
    packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:344: package R does not exist
            menu.add(0, MENU_SAVE, 0, R.string.menu_save)
                                       ^
    packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:346: package R does not exist
            menu.add(0, MENU_CANCEL, 0, R.string.menu_cancel)
                                         ^
    packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:454: package R does not exist
                         errorMsg = mRes.getString(R.string.error_empty);
                                                    ^
    packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:458: package R does not exist
                         errorMsg = mRes.getString(R.string.error_empty);