Tom Xue
Tom Xue

Reputation: 3355

Why my R.java cannot be generated automatically?

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!

Upvotes: 0

Views: 145

Answers (4)

Dzhuneyt
Dzhuneyt

Reputation: 8701

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.

Upvotes: 0

Gunhan
Gunhan

Reputation: 7035

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.

Upvotes: 1

An-droid
An-droid

Reputation: 6485

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

Upvotes: 0

Prasoon Katiyar
Prasoon Katiyar

Reputation: 1

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

Upvotes: 0

Related Questions