R cannot be resolved – Android error

After tracking down this problem as well, I found this note in the Android documentation:

http://source.android.com/source/using-eclipse.html

*Note: 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
will cause your make to break. Look
out for these erroneous import
statements and delete them.*

While going through the Android sample tutorials, I would often use the Ctrl + Shift + O command to “Organize Imports” and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.

Leave a Comment