1

I know this question has been many times but trust me I have checked all. Most of the question suggests to remove import android.R , remove any error in the xml file, checking name of the files (no capital letters) then rebuild and clean the project or restart eclipse. I have tried all but none solved the problem. The problem occured when i cleaned all the projects. Now all the projects are showing that error. Since all the project were running perfectly before i cleaned projects, there is no possibility that all of the sudden the layouts or the file names of all the projects have error in them.

Also there is no file in gen folder. As far as i can understand there is something wrong with the build path or preferences can anyne point me in a correct direction? o!

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • http://stackoverflow.com/questions/16642604/eclipse-error-r-cannot-be-resolved-to-a-variable/16643060#16643060. try this – Raghunandan Jul 03 '13 at 05:52

2 Answers2

1

Make sure you installed the Android build tool form sdk manager

project right click properties-> Java BuildPath select Library and add android-support.jar the follow these step.

Go to Project->Properties->Java Build Path than select Order and export tab. Set android-support .jar library checked and up it into top of the list. And clean and rebuild..It works for most of the cases

enter image description here

Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
  • how to add `android-support.jar`. I clicked on `Add Library` then what? – Rohan Kandwal Jul 03 '13 at 07:02
  • clicked on Add Library then add external jar and then click ok and same for Order and export tab checked the check box of android-support .jar and click ok button and then clean and build your projects – Sunil Kumar Jul 03 '13 at 07:06
  • I think you added the android-support.jar file,Make sure you installed the Android application tool form sdk manager ?, if installed then everything looks right need to restart the eclipse – Sunil Kumar Jul 03 '13 at 07:25
  • 1
    see this link and see the first one Tool and checked that installed both of tool in your sdk manager http://developer.android.com/tools/help/sdk-manager.html – Sunil Kumar Jul 03 '13 at 07:29
  • really sorry to bother you but i am still confused. I did this project right click properties-> Java BuildPath -> Add Library. Now i have an option to select the library type i want to add. What should i do? – Rohan Kandwal Jul 03 '13 at 07:30
  • ya i updated eclipse yesterday and yes android sdk build tools are not installed. But it was running fine yesterday and also in the morning until i cleaned the projects. I am installing the build tools at the present. – Rohan Kandwal Jul 03 '13 at 07:32
  • okay now install this tool and then clean and build error will gone – Sunil Kumar Jul 03 '13 at 07:35
  • ok that solved the `R` problem but now it is showing missing `AndroidManifest.xml` although it is present there. – Rohan Kandwal Jul 03 '13 at 07:52
  • reimport the AndroidManifest.xml file or make a change to the file and save it. or clean and build your project – Sunil Kumar Jul 03 '13 at 08:18
  • Cleaning the project did the trick. I am really fed up from eclipse have to face some error every once in a while.Anyway Thanks.. – Rohan Kandwal Jul 03 '13 at 08:45
1

Check the answer here and the thread here. Check if your layouts contain any errors (this has to be done manually or automatically only with Android Studio). Search for incorrectly closed tags like <string> - </string>.

EDIT (taken from this thread):

Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.

Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.

  • After you have deleted the gen directory, go to Project > Clean ...
  • You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
  • Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.
Community
  • 1
  • 1
g00dy
  • 6,752
  • 2
  • 30
  • 43
  • i already said that the problem arrived after i cleaned the projects. Also you can see from my screenshot that all of my projects have that error. I don't think that suddenly all the xmls have developed that problem. I think it is something with the imports. – Rohan Kandwal Jul 03 '13 at 07:05
  • That problem occurs, in most of the cases, when you have an error in one of your layouts, as already said. You should quadriple check everything there, just to be sure. - I edited my answer to add more info of how to deal with this problem. – g00dy Jul 03 '13 at 07:09
  • i am checking the xml files meanwhile please see my screenshots to detect any missing imports – Rohan Kandwal Jul 03 '13 at 07:13
  • Can you paste them here too if they're not too big? – g00dy Jul 03 '13 at 07:27
  • they are pasted here see my question – Rohan Kandwal Jul 03 '13 at 07:28
  • I was speaking about the xml files :) – g00dy Jul 03 '13 at 07:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32795/discussion-between-rohan-kandwal-and-g00dy) – Rohan Kandwal Jul 03 '13 at 07:34