0

I just installed Eclipse on my computer. And I make a blank Android project via its wizard step by step. That means this project should work fine after it is created. But it cannot and show error of "R cannot be resolved to a variable". And I found that the gen directory is empty and it won't generate anything new in this directory even that I try to Clean and select Build Automatically option already.

I download an existing Android project from my Github and it can work. But after I run Clean, it gave the same Error information and its gen directory is empty again.

Why and how to solve it? Thanks!

Tom Xue
  • 3,169
  • 7
  • 40
  • 77
  • check your resources files if you have any errors. if there is any error then R.java is not generated. – Raghunandan Jul 19 '13 at 08:38
  • if you haven't errors, open one layout and modify it and save then eclipse regenerate R – Alex Muni Jul 19 '13 at 08:41
  • Here Its not because of resource error. Even new projects without any edit misses its R file. May be because of ADT plugin/sdk error, I think. – Nizam Jul 19 '13 at 08:44
  • Check: [Eclipse error: R cannot be resolved to a variable](http://stackoverflow.com/questions/16642604/eclipse-error-r-cannot-be-resolved-to-a-variable/16643060#16643060) – Paresh Mayani Jul 19 '13 at 08:50
  • http://stackoverflow.com/questions/16584015/java-eclipse-no-more-r-file-ever/16584243#16584243 – Michael Shrestha Jul 19 '13 at 08:50

4 Answers4

1

Make sure that you have installed the followings in Android SDK Manager

Android SDK Tools

Android SDK Platform-tools

Android SDK Build-tools

By clicking Window-> Android SDK Manager in Eclipse

Wait a bit to let it fetch the content and you will see if they are installed or not.

Nizam
  • 5,698
  • 9
  • 45
  • 57
Gunhan
  • 6,807
  • 3
  • 43
  • 37
  • One of those tools is not installed, and I installed it. Then I made a reboot, the issue was resovled. Thanks! – Tom Xue Jul 19 '13 at 09:01
0

It is an error of Eclipse. Create a new Project, copy all the scr and res file to new Project. It will work fine.

0

1- Check for errors, if there are just comment it. The idea is to build the project et reconstruct the /gen. After that you can uncomment in good order.

2- Use Clean/refresh/build as many as you need.

3- Sometimes eclipse needs to be restarted..

4- Try to reinstall your sdk tools

5- If nothing is working you should concider reinstalling your ADT if you are using the bundle. If you are using classique eclipse reinstall android sdk retry and if it's still not working reinstall eclipse too.

hope it helps

An-droid
  • 6,433
  • 9
  • 48
  • 93
0

Most of the times the error comes from wrong formatting in the XML files, which Eclipse doesn't always detect.

Make sure to go through the XMLs and check for potential errors.

If all looks good, rebuild the project.

If that fails restart Eclipse.

If that also fails, as a last resort - copy your project somewhere, reinstall Eclipse and Android SDK tools and re-import your project.

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118