why does R does not exist error come in android?

garima picture garima · Dec 27, 2010 · Viewed 30.9k times · Source
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);

Answer

Trebor Rude picture Trebor Rude · Apr 5, 2013

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.