Missing R.java file even though project cleaned

James picture James · Oct 4, 2011 · Viewed 41.9k times · Source

Every time in code that I have an R, I get an error R cannot be resolved to a variable.

The R.java file appears to be missing.

I have tried cleaning the project.

Answer

superM picture superM · Oct 4, 2011

This can happen when you have an error in one of your xml files (for example, a resource cannot be found). This can also happen because of using menus (I have had this problem because of menus, and I had to remove them, clean and add them again). And another possible reason is that you initially wanted to have your R class not in the default place where it is created but in your own package. So it is possible that R is created in its default location and your program is looking for it somewhere else.