Ok, I am working on a new app and everything worked fine as long as I used a Relative View. However, I want a tabbed layout so I switched what I had (not much so far since
In my case it was caused since I refactored my project and moved some classes inside a folder structure. Those classes couldnt find the R as usual, since its based on the root source folder.
Check that all of the strings you think you're using (e.g. "@string/Hello_world") actually exist in your strings.xml file. I got the OP's error after declaring a menu item using android:title="@string/Navigation"
, but I hadn't added <string name="Navigation">Navigation</string>
to strings.xml
Along with the great suggestions in the previous answers, make sure your Android target is set:
Edit: A year later I found another cause. I had a .jpg image in my drawable folder with the same name as a .png image. Referencing this image in my code must have confused the program and it gave the "R cannot be resolved" error.
I had the sample problem too and this worked for me.
1.) Check for any errors in your Layout XML. Especially when it comes to text and titles
You should use
android:text="@string/hello"
instead of
android:text="hello"
.2) Clean your project
.3) Restart Eclipse
If you're using Eclipse, trying giving it a kick by doing a Project/Clean and re-building your project. It sometimes has random trouble with the classpath on Android projects.