Android - R 无法解析为变量

发布于 2024-10-16 03:57:05 字数 419 浏览 8 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

假情假意假温柔 2024-10-23 03:57:05

我想我找到了这个问题的另一个解决方案

转到项目>属性> 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
enter image description here
Then if your workspace does not build automatically…

Properties again > Build Project
enter image description here

酷炫老祖宗 2024-10-23 03:57:05

您的目标是 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!

一腔孤↑勇 2024-10-23 03:57:05

我已经很容易地解决了我的问题:
转到 Build- Path->Configure Build Path->Order and Export 并确保 /gen文件夹位于 /src之上>
修复订单后错误消失。

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.

小帐篷 2024-10-23 03:57:05

检查您的 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_.

末蓝 2024-10-23 03:57:05

您想要干净项目
像这样

点击

Projects>Clean>select your project

这个会对你有帮助

You want Clean Project
Like this

click on

Projects>Clean>select your project

this will help to u

莫多说 2024-10-23 03:57:05

同意这可能是由于资源问题导致无法在 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.

私野 2024-10-23 03:57:05

与同样的问题斗争了大约一个小时。我终于意识到我正在引用 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.

树深时见影 2024-10-23 03:57:05

保存所有布局,并将其替换为以前的版本。开始一项一项地复制并每次都清理项目,有时其中一个布局有一些 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文