Pages Navigation Menu

Coding is much easier than you think

R cannot be resolved – Android error

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:

import android.R;

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 /resdirectory 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.xmlfile. It uses your Android package name to create a subdirectory under the “gen” directory where it stores the R.javafile.

You can either rename the subdirectory under gento 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 R.javafile.

About Gokul


I am very much interested in android and Wicket framework. A core android developer and working in android native app development and responsive web mobile design. I have also worked in wicket fame work and java web development. I will keep on updating you about android and wicket framework and answer your query.