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 replies
  1. Anonymous
    Anonymous says:

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

    Reply
  2. Tushar
    Tushar says:

    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 :)

    Reply
  3. Tariel
    Tariel says:

    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.

    Reply
  4. M.Zed
    M.Zed says:

    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 !

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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