1

I know there are a lot of questions similar to this one. But I have tried the solutions and none are working. I thought one of the following should work: 1. Getting rid of 'import android.R' line. 2. Cleaning the project and then building it again.

Still I have the same old "R cannot be resolved to a variable" problem. The gen folder is empty.

user1357350
  • 777
  • 1
  • 7
  • 12

6 Answers6

6

I've had a similar issue some days ago. My R.java was not regenerated after I cleaned my project. Here is what fixed it for me: It seems like as of SDK version 22, which I had recently downloaded, there is an additional package you have to download from the SDK manager called "Android SDK build-tools". Without this package, Eclipse will not generate R. I installed it, restarted Eclipse and everything was working again. I had found the solution on StackOverflow: https://stackoverflow.com/a/16643060/1691231

Community
  • 1
  • 1
Shah
  • 385
  • 1
  • 6
  • 15
4

This usually means that you have a problem with one of your resources so R cannot be generated. Check the layout XMLs and see if one of them have a warning / error.

After removing the error please clean the project Project->clean

Jitendra
  • 1,015
  • 9
  • 24
MByD
  • 135,866
  • 28
  • 264
  • 277
  • There was a small error in one of the xml files. I corrected it and now there is R.java in gen folder. But the error is still there. – user1357350 May 14 '12 at 12:10
  • What do you mean the error is still there? have you tried clean / rebuild after you fixed the error? – MByD May 14 '12 at 12:14
  • 1
    Got it fixed! There was a small change in the package name in the manifest file. It was not flagged as an eror, so I missed it. After I fixed that, done the clean/build, it worked. Thanx for ur help. – user1357350 May 14 '12 at 12:42
2

This may occur because of your project has errors, Please try to clear the errors, remove 'import android.R' line and Clean and build the Project.

Ponmalar
  • 6,871
  • 10
  • 50
  • 80
0

Try this:

at first fix your layout errors.

then go to menu project-> clean and select your project

Bob
  • 22,810
  • 38
  • 143
  • 225
0

This also generally means something wrong with the build process...Have a look at the libraries tab under Java Build Path option in project properties dialog.....

Kunal Shah
  • 489
  • 1
  • 4
  • 21
0

Check your XML resources (especially these recently edited) for mistakes and sytax errors. When you have an error inside one of these files, the R class autogeneration will abort.

Devendar
  • 323
  • 1
  • 4
  • 20