Fixed: R cannot be resolved to a variable


I encountered this problem when I was making a new project on my eclipse workspace. I got a red underline on “R” in this part of my code

setContentView(R.layout.main);

So here’s what I did to fix this issue. Go to Project Properties > Java Build Path > Tick Android Version Checkbox

rcannotberesoved
Then if your workspace does not build automatically…

Properties again > Build Project

buildproj
After that, all went back to normal. :)
Thanks for reading this Fixed: R cannot be resolved to a variable!


24 responses to “Fixed: R cannot be resolved to a variable”

  1. Resolving R error: I in general try to save, debug or run again n again to remove this error….nice solution :-)

  2. wow… Finally it worked thanks you are genius.
    (Yesterday i updated my eclipse version into Juno and also the android sdk to 4.1 after that i was facing the ‘R cannot be resolved to a variable’ problem)
    But now its Absolutely Fine..

    :) thanks :)

  3. This helped a ton with my file path problem when trying to add an audio file [ex: mp1 = MediaPlayer.create(this, R.raw.audiofile); but only after I made sure that the audio file name was in ALL lowercase. The error popped up only while the audio name had a cap in it like: audioFile.mp3. Until the mp3 name was switched to all lowercase the path could not be resolved.

  4. I had this problem for weeks ! I tried every thing that was in the websites ! and now the problems are gone ! i didn’t get what happened ! but so happy … thank u a lot !

Leave a Reply

Your email address will not be published. Required fields are marked *