I would like to fix this error
R cannot be resolved to a variable
I looked up many answers, but I could not get the right one;
I have just had this problem.
It was caused because I had a redundant menu resource that referred to a non-existing string.
Removed the menu XML and back came R.
If you haven't yet, try cleaning your project as already suggested. In Eclipse Indigo, this is Project -> Clean... -> (Make sure your project(s) are checked) -> OK. After that, right click on your project and choose "Refresh".
If this is still a issue, a few questions:
Check your AndroidManifest.xml file, see if the package name is correct. If you copied an example it is likely this is wrong and the source of your problem.
Check if the package name in the AndroidManifest.xml file is the same than the package name of your java class.
Eg. AndroidManifest.xml
package="com.example.de.vogella.android.widget.example"
In your class MyWidgetProvider.java
package com.example.de.vogella.android.widget.example;
It was the cause of my error in this example.
If Clean/Rebuild Project doesn't work try to check our package name in AndroidManifest.xml.
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 R.java file.
I just had this error on my first hello world android application (3-Nov-2013).
Along with a few pointers from other users, this is what I had to do:
Control+Shift+O
Delete the import *.R from the top of the main activity .java file
Save the file, clean and compile the project (usually build is automatic)
Run SDK Manager, enable the build tools if not already checked, and hit Update regardless
Close and reopen Eclipse and the problem was gone