This is the most common error encountered while working with Android Eclipse ADT or Android Studio IDE. You get this error if R.class file is not generated under gen folder, this file is auto generated every time the build happens, if there is any error encountered while build you get R Cannot Be Resolved to a Variable.
There are many reasons that may cause this error. I am trying to list down as many reasons as I can to my knowledge.
1. R.java Class Import
Check if android.R import statements are present in any of your Java files under src folder, it is not required as R is static class, but many a time we do Ctrl + Shift + O which causes this import statement being added.
Eclipse somethings cries for these imports but just don't add them, the problem is due to some other stuffs like layouts or drawables.
Drawables (images) or xml's contained here are the real culprits most of the times for such issues. You won't even see a red error cross displayed over the drawable folder (but if you clean and build your project you would find the error messages displayed under logCat console)
Check that images and XML files follows the below mentioned naming conventions,
- All file names must be in lower-cases
- Files under drawables must not contain any special characters other than _ (underscore)
- Files must not contain numeric values.
If you have changed the package name for your app in the Manifest file, this may not generate R.class resulting in such a error. Make sure you clean and build.
4. Check Order of Export
Right-Click on you project
Java Build Path
Order and Export
5. Check if Android Target is set.
Right-click on your Project Folder.
Check the box next to appropriate Project Build Target.
Click Apply and OK.
- Android appcompat_v7 Error retrieving parent for item: No resource found that matches the given name
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- Center align text in TextView Android Programming
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Android : Remove ListView Separator/divider programmatically or using xml property
- Copy Text to Android Clipboard Programmatically ClipboardManager
- How to add Newline to text in Android TextView
- How to Change Android Toast Position?
- Android AlertDialog with 3 buttons example
- The declared package does not match the expected package Eclipse - Android
- JSON Tutorial: List of Lessons - Json-Tutorial
- Android : No Launcher activity found! Error - Android
- Set Title to Android AlertDialog - Android
- Android AlertDialog with Yes No and Cancel Button - Android
- New-SPLogFile PowerShell - create new SharePoint log file - SharePoint
- Get HTML table td, tr or th inner content value with id or name attribute - Html
- Center Align TextView Android Horizontally or Vertically - Android
- NOTE: This project contains resource errors, so aapt did not succeed, which can cause rendering failures. Fix resource problems first. - Android
- Android Disable back button programatically - Android
- How to make a dummy phone call from Android Emulator device - Android
- How to extract deployed WSP solution from SharePoint FARM using PowerShell - SharePoint
- Kill or force quit stuck application or process in Mac OS X - Mac-OS-X
- Deploy SharePoint wsp solution package using PowerShell - SharePoint
- Calculate Volume of Sphere - C-Program