Android - R 无法解析为变量
可能的重复:
R 无法解析 - Android 错误
我遇到了一个问题以前,我不明白原因。我的项目和代码很好,因为它昨天正在运行。我今天打开了 Eclipse,整个项目看起来都包含错误。
我相信这是某种构建路径问题。我不明白为什么它会随机发生?但是在有 R.Layout.LayoutName
的代码中存在一个问题......任何人都可以帮忙吗?
我尝试过清理和构建它,我尝试过导入 android.R 但我之前没有这个,然后它给出错误并说布局文件不存在。
Possible Duplicate:
R cannot be resolved - Android error
I am having a issue which I have had before and I don't understand the cause. My project and code is fine as it was running yesterday. I have open Eclipse today and the whole project looks like it contains errors.
I believe it is some sort of build path issue. I don't understand why it randomly occurs? But in the code where there is R.Layout.LayoutName
there is an issue... can anyone help?
I have tried cleaning and building it, I have tried importing android.R but I didn't have this before, it then gives and error and says the layout file doesn't exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我想我找到了这个问题的另一个解决方案 。
转到项目>属性> Java 构建路径 >选项卡[订单和导出]>勾选 Android 版本复选框
然后,如果您的工作区没有自动构建...
再次属性>构建项目
I think I found another solution to this question.
Go to Project > Properties > Java Build Path > tab [Order and Export] > Tick Android Version Checkbox
Then if your workspace does not build automatically…
Properties again > Build Project
您的目标是 android.R 还是您自己项目中的目标?
您确定生成了您自己的 R.java 文件吗? xml 视图中的错误可能会导致无法生成 R.java。检查您的视图文件并确保所有 xml 都是正确的!
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!
我已经很容易地解决了我的问题:/gen 文件夹位于 /src 之上>
转到 Build- Path->Configure Build Path->Order and Export 并确保
修复订单后错误消失。
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.
检查您的 R 目录...有时,如果文件名不全是小写并且包含特殊字符,您可能会收到此错误。我使用 eclipse,它只接受文件名 a-z0-9_。
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_.
您想要
干净
项目像这样
点击
这个会对你有帮助
You want
Clean
ProjectLike this
click on
this will help to u
同意这可能是由于资源问题导致无法在 gen 中构建 R.Java。就我而言,剪切和粘贴在字符串中给出了重复的应用程序名称。排查故障,删除gen目录并清理。
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.
与同样的问题斗争了大约一个小时。我终于意识到我正在引用 xml 文件中的一些图像文件,而我的 R.drawable 文件夹中还没有这些文件。当我将文件复制到文件夹中后,问题就消失了。您需要确保拥有所有必要的文件。
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.
保存所有布局,并将其替换为以前的版本。开始一项一项地复制并每次都清理项目,有时其中一个布局有一些 Eclipse 不喜欢的东西。这对我有用。
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.