0

Tell me the possible solution for R.java file missing or "R cannot be resolved to a variable" I have tried the following still R cannot be resolved as a variable error is coming.These are the following things i have tried:

Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.

If you somehow hit something and created import android.R in your activity, remove it. Run Project -> Clean. This will delete and regenerate R and BuildConfig.

Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .

Wait a few seconds for the errors to disappear.

If it doesn't work, delete everything inside the /gen/ folder

If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.

Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.

Right-click your project > properties > Android.

Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.

What to do if R doesn't regenerate

This usually happens when you have a broken xml file.

Check errors inside your XML files, mainly within the /res/ folder

Common places are /layout/ and /values/ especially if you've changed one of them recently

Check AndroidManifest.xml, I find that often I change a string, and forget to change the string name from AndroidManifest.xml.

Check that Android SDK Build-tools is installed. Window->Android SDK Manager->Tools->Android SDK Build-tools

Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ASK Build-tools. Build fails silently if they don't match.

If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. This doesn't solve the problem, but it will clear out the extra errors to make the problem easier to find.

Heraj Mishra
  • 21
  • 1
  • 7
  • 2
    did you try cleaning and building your project??.. Works for me 8 out of 10 times... – TheLostMind Dec 27 '13 at 11:47
  • May be any xml resource is missing. – keshav Dec 27 '13 at 11:51
  • Either your project have error which stops project to builds and its result no R file created. Check the problem tab on bottom of Java perspective , it will shows error which stopping building the project. – Roll no1 Dec 27 '13 at 11:55
  • Please visit below link: http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable?rq=1 – rupesh Dec 27 '13 at 11:57

3 Answers3

0

I believe you give the effort but only the problem is XML Error in your layout file.You give a wrong id or something like that.Because this also happened with me and finally i found the error in my xml file and when i fix that error and pressing CTRL and Key S.Eclipse builds the R file..! I also suggest you to get the R file from project backup and again give a try.

Kailash Dabhi
  • 3,473
  • 1
  • 29
  • 47
0

always check your res folder first, if there is an error there, the build will fail, resulting to no generation of the gen files

TootsieRockNRoll
  • 3,218
  • 2
  • 25
  • 50
0

There is some error in your Xml code. What you have to do is find it and correct it. it may be any error like hwight and width not specified for some view. once You have done it your R.jaav will be created just fine. if still not so clean Your Project and recompile will do the Trick.

Ana
  • 841
  • 10
  • 28