Fixed: R cannot be resolved to a variable

Published by - @ninjazhai on May 31, 2011
LIKE and SHARE:

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

Click to enlarge.

Click to enlarge.

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!

The Code of a Ninja Resources

  • Anonymous

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

  • http://www.blogger.com/profile/05733400401287031490 Mike Dalisay

    Thanks for your suggestion and comment Anonymous :)

  • Anonymous

    Great tip. Ticking the Android checkbox fixed the problem. Thanks!

  • http://www.blogger.com/profile/05733400401287031490 Mike Dalisay

    You’re welcome @Anonymous. :)

  • http://www.blogger.com/profile/13413851041297105642 Tushar

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

  • Anonymous

    though that is a great solution. it did not work for me.