R cannot be resolved – Android error
This maybe due to following Reasons:
1. Eclipse sometimes likes to add an “import android.R” statement at the top of your files that use resources, especially when you ask Eclipse to sort or otherwise manage imports. This might have been added when you use Ctrl+Shift+O keys for Organizing the Imports. So this has to be deleted.
Look at your imports. Chances are that the line:
will be there. If that’s the case, remove it, so that your project will resolve R not with the default Android Resources class, but with the one auto-generated from your /res/ folder.
2. Check for the
/res directory and there must be some file that have some error in it and that is preventing the application from being built. For example, it may be a layout file or image file or it may be due to some missing resource that defined in the XML file, but not included in the image resources.
3. The problem “R cannot be resolved” happens when you change your package name in the
AndroidManifest.xml file. It uses your Android package name to create a subdirectory under the “gen” directory where it stores the
You can either rename the subdirectory under
gen to match your new package name, or you can change your package name back to the old name.
You can also do following steps:
1. Delete import R.java in your activity.
2. Under the “Project” menu uncheck the option to “Build Automatically”.
3. Select “Project” -> “Clean” on the Eclipse menu, it will remove and then regenerate the