Fresh install of Eclipse, R cannot be resolved to a variable [duplicate]

只愿长相守 提交于 2019-12-03 14:00:18

I had the same issue. Fresh install of ADT Bundle, creating a new project using wizard, was giving me "R cannot be resolved to a variable" error. I tried everything explained in previous post.

In my particular case, it was that I had another copy of Android SDK tools and ADT Bundle was pointing to that one, instead of the one that comes with the bundle. I just changed that, and all projects were working again. Hope this helps.

sudo apt-get install ia32-libs

Some quick solutions to your problem might be,

  • use the Ctrl + Shift + O command to "Organize Imports" and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.
  • R is a generated class. If you are using the Android Development Tools (ADT) it is generated whenever the project is built. You may have 'Build Automatically' turned off. Turn it on and build your project.
  • Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!
  • Remove, if any import android.R;
  • Restart your IDE, if it is just installed.

There are two solution for this, it will solve your problem.

1) Build your project.

2) Go to Project > Clean and the Clean your project.

All other answers are correct, but make sure that any layout don't have any error inside, otherwise eclipse will not generate R.java file. So first try to solve any layout errors and then apply Clean Project and build one more time.

If error comes, remove gen and bin directory and one more time try to build project.

I have had this issue with Eclipse, and it was because I had deleted the bin and gen directories, and Eclipse did not have permissions to recreate those directories. Fixed with chmod.

user2449959

Make sure that all the SDKs are updated. In Eclipse go to Help -> Updates and use the SDK Manager to make sure everything is updated.

Restart your IDE. R - kind of resource handler - will be auto generated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!