1

So , this Morning ,

  • i launched Eclipse ,

  • i do somes Modification on a String , on Res/Value/String.xml ,

  • i modified Juste One String , then i saved , i get "R Cannot be Resolved to a Variable" Error ,
  • Then i undo my Modification on this String ,
  • i tried to Clean my Project , i have Checked all Ressource Name/Files , i Checked for Update on Eclipse(Notice that i have Updated Adb/Eclipse/SDK Just somes Days ago ...) ,
  • & Now , "R Cannot be Resolved to a Variable" Error Affect All my Projects into Workspace ,

I had Already this Error before but i fixed it , but Now im Lost ,

Anyone Know something about that Error ?

Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74

3 Answers3

0

Have a look at the import statements.

Does it say import android.R? Delete that line and import R again, making sure it's the one from your project's package, not Android's.

gleerman
  • 1,793
  • 4
  • 24
  • 38
  • Already checked , & no android.R & No Visible Error on my Xml Files –  Jun 28 '13 at 10:14
0

You mentioned you updated updated Eclipse.. so try this..

  • Start Android SDK Manager
  • Look for any more updates available..
  • Install updates and restart Eclipse
  • Also go to Help->Check for Updates and install updates.

repeat the last two step mentioned above till you get no updates available.

Restart Eclipse Again and the check..

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
  • Yes i have Updated Everything & no there is No Update avaible anymore –  Jun 28 '13 at 10:27
  • Are you sure your own R.java file is generated and there is no error in your xml files...?? – CRUSADER Jun 28 '13 at 10:34
  • No , sorry i have not Mentionned , i have Lost(i have No) R.java File anymore gen & bin Folder are empty & i have a assets/fonts/ Folder & a File "A.ttf" inside but this assets Folder look like Empty in Eclipse IDE –  Jun 28 '13 at 10:36
  • Ok, create a new ANdroid project, a simple Hello world project, check the issue still remains, if not, then, solution is simple create a new project and add all related files. (Note donot import project but add files) – CRUSADER Jun 28 '13 at 10:39
  • Ok , i have Created a New Project "Hello World" & i get the same "R Cannot be Resolved to a Variable" Error , Please notice that i have Unchecked "Android" on Properties>Java Build Path just before to try to Resolve this Issue –  Jun 28 '13 at 10:49
  • Why did you do that for,Go Project Properties > Java Build Path > Order and export --> Tick Android Version Checkbox,, this could be one of solution... restart eclipse then... – CRUSADER Jun 28 '13 at 11:01
  • Thats Crazy Fcking Error !! –  Jun 28 '13 at 11:20
  • right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. This will not solve the problem, but it will clear out the extra errors to make the problem easier to find.. You get to know if there where actually error in layout, or drawable etc.. – CRUSADER Jun 28 '13 at 11:28
  • Thanks for your Help , but i get a Message "No deleted Ressources in local history for the Selected Container" –  Jun 28 '13 at 11:50
  • Oh boy!! Hmm, I hope you must have maintained backup of your project at some point of time, try copy that R.java file inside your project, then save-- refresh project-- clean and build your project.. – CRUSADER Jun 28 '13 at 11:57
  • Yes , but there were Many Many Changes since my Last Backup –  Jun 28 '13 at 12:04
  • Its ok, just copy it, I am expecting eclipse to overwite it once you clean and build...Try it for once.. – CRUSADER Jun 28 '13 at 12:05
  • Ok , ill try ... so i am going to get the R File from my Last Backup & put it into my Project , but Why All My Projects are Affected with this Error , is there Something Wrong with Eclipse/SDK ? –  Jun 28 '13 at 12:28
  • Does no Work , Gen Folder still appear as Empty in Eclipse –  Jun 28 '13 at 13:17
0

Perform the following steps in your Eclipse

  1. Right click on your Project name and select Properties.
  2. Click on Android on make sure the Target name under the Project Build Target is checked. If not, enable the checkbox.
  3. Click on Apply
  4. Right click on your Project again and select build bath and then Configure Build Path
  5. Under the Order and Export make sure the Android Library and any other referencing Libraries and selected.
  6. Click on OK
  7. Now Clean and build your project again and it should resolve the issue

Thanks Ameya

  • 2. Android 4.0 was already Checked 5. Android 4.0 was Unchecked , i Checked it Then Cleanned my Project , but this does Not Resolve my Issue :( , & i say Again , All my Projects are Affected with the Same Error ... –  Jun 28 '13 at 13:20
  • Did you perform steps 4-7? you need to perform steps 4-7 as well, try it! –  Jun 28 '13 at 13:22
  • Yes , i did All Steps you Mentionned –  Jun 28 '13 at 13:27
  • OK, hover your mouse over the Android.R variable and click on Fix project setup, this will provide you with an option to select the SDK, select it and your error should go away –  Jun 28 '13 at 13:29
  • mouse over Android.R Variable ? What is that , i have already tried Android Tools>Fix Project Properties , Maybe Unistall Eclipse/SDK and Reinstall All ? –  Jun 28 '13 at 13:30
  • Clicking on Fix Project Properties from Android tools doesn't work at times. It didn't work for me when I was trying to resolve the issue. I resolved it by actually hovering/moving my mouse pointer over the R and clicking on Fix Project Properties, you might want to give it a try –  Jun 28 '13 at 13:33
  • My Bad :/ Sorry All i just Noticed "Android SDK-Build Tools" isnt Installed as @Ken Wolf & CRUSADER Said ill try to Install it Now ... –  Jun 28 '13 at 13:34
  • Problem Fixed :) , Thanks All & Stack Overflow for your Help especially @Kev Wolf & CRUSADER , My Problem is that i have Updated Everything somes days ago & "Android SDK-Build Tools" was Not Installed –  Jun 28 '13 at 13:38