Android-R 不能解析为变量

可能的复制品:
无法解析 R-Android 错误

我有一个问题,我以前有过,我不明白的原因。我的项目和代码运行得很好,就像昨天一样。我今天打开了 Eclipse,整个项目看起来好像包含错误。

我相信这是某种构建路径问题。我不明白为什么会这样?但是在 R.Layout.LayoutName的代码中有一个问题... 有人能帮忙吗?

我尝试过清理和构建它,我尝试过导入 android.R,但我以前没有这个,然后它给出错误,并说布局文件不存在。

177218 次浏览

You want Clean Project Like this

click on

Projects>Clean>select your project

this will help to u

Are you targeting the android.R or the one in your own project?

Are you sure your own R.java file is generated? 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!

I think I found another solution to this question.

Go to Project > Properties > Java Build Path > tab [Order and Export] > Tick Android Version Checkbox enter image description here Then if your workspace does not build automatically…

Properties again > Build Project enter image description here

check your R directory ...sometimes if a file name is not all lower case and has special characters you can get this error. Im using eclipse and it only accepts file names a-z0-9_.

Fought the same problem for about an hour. I finally realized that I was referencing some image files in an xml file that I did not yet have in my R.drawable folder. As soon as I copied the files into the folder, the problem went away. You need to make sure you have all the necessary files present.

I've fixed the problem in my case very easy:
go to Build- Path->Configure Build Path->Order and Export and ensure that <project name>/gen folder is above <project name>/src
After fixing the order the error disappears.

Agree it is probably due to a problem in resources that is preventing build of R.Java in gen. In my case a cut n paste had given a duplicate app name in string. Sort the fault, delete gen directory and clean.

Save all layouts, and replace them from the previous version. Start to copy one by one and clean the project everytime, sometimes one of the layouts has something, that eclipse doesn't like. It worked for me.