Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does R does not exist error come in android?

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);
like image 913
garima Avatar asked Dec 27 '10 04:12

garima


People also ask

What does R stand for in Android?

(Pocket-lint) - Google has revealed the 'tasty treat' name for its latest version of Android. Turns out that 'R' stands for 'Red Velvet Cake. Yum! Prior to Android 10, Google used tasty treat names for almost every version of Android as a public name.

What is Package R in Android Studio?

The R class is generated automatically from the application's resources. It contains the id s for these resources and is contained in the package named in the <manifest> tag in the corresponding AndroidManifest. xml file. If there are no errors in the resource XML files, the R.

Where is the R file in Android Studio?

R. java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.


3 Answers

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

like image 130
Eugene Avatar answered Oct 10 '22 00:10

Eugene


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.

like image 39
Trebor Rude Avatar answered Oct 09 '22 23:10

Trebor Rude


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.

like image 12
michaelg Avatar answered Oct 09 '22 23:10

michaelg