R 无法解析-android(尝试了常见修复)

发布于 2024-12-21 10:35:30 字数 254 浏览 0 评论 0原文

好吧...我知道这是重复,但是我的 xml 没有任何问题。 r 未导入,我已尝试清理我的项目。

当我在我的drawble文件夹中添加一个.png并将其删除并且错误仍然存​​在时,它就开始了。我不知道还能尝试什么,但这真的很令人沮丧。

我还尝试创建新项目和错误生成器。

更新*我做了所有这些事情,但在我的第一个项目中没有一个起作用,但是当我创建一个新项目时它起作用了吗?在它没有之前,所以有人修复了它!我只需将我的代码转移到该代码即可。 谢谢大家

okay... I know this is a repeat but, nothing is wrong with my xml. r isn't imported and I have tried cleaning my project.

It started when I added a .png in my drawble folder and I removed it and the error still protists. I don't know what else to try but it is really frustrating.

I have also tried to create new project and the error generators on those too.

Update* I did all of these things and none worked on my first project, but when I created a new one it worked? and before it didn't so something fixed it! I will just transfer my code to that one.
Thank you everyone

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

羁绊已千年 2024-12-28 10:35:30

尝试删除R文件,它会自动重新创建&这可能会解决问题。您可以在此处找到 R 文件:

Your Project >> gen >> your package Name >> R.java

Try to delete the R file, it will be automatically recreated & this may resolve the issue. You can find the R file here:

Your Project >> gen >> your package Name >> R.java
淡墨 2024-12-28 10:35:30

仔细检查您的 java 源文件,看看是否有“import com.company.R;”明确定义的语句。如果是,请删除它们,然后对您的项目进行清理。 “导入com.company.R;”不应该在 java 源代码中显式定义。

在某些情况下,Eclipse 会尝试通过默默地添加“import com.company.R;”来为我们进行一些自动修复。对于您的 java 源,这不会对现有导入的项目造成任何问题,因为此时已经生成了 gen 文件夹和 R java 文件。但是,如果您删除带有 R.java 的 gen 文件夹,然后尝试再次将项目全新导入 Eclipse,则格式错误的 java 源(带有“import com.company.R”的源)将使 ADT 在尝试生成/解析 R 时感到困惑.java 从头开始​​。结果,您收到一堆编译错误警告“R 无法解析”。

希望这能解决您的问题。

Double check your java source file to see if there are any that have "import com.company.R;" statement explicitly defined. If yes, delete them then do a clean on your project. "import com.company.R;" should be never explicitly defined in java source.

In some situation, Eclipse attempt to do some auto fix for us by silently adding "import com.company.R;" to your java source, this does not cause any problem on the existing imported project as the gen folder and R java file has already been generated at this point. However, if you delete gen folder with R.java then trying to fresh import the project into Eclipse again, the malformed java source (those with "import com.company.R") will make the ADT confused when trying to generate/resolve R.java from scratch. As the outcome, you got bunch of compilation error warning "R cannot be resolved".

Hope this solve your problem.

左耳近心 2024-12-28 10:35:30

我不确定这是否有帮助,但是 Eclipse 中的一些构建问题可以通过删除错误来解决。只需转到 Eclipse 的问题视图,选择错误并按键盘上的删除即可。然后再次清理项目并构建它。

I'm not sure if this can help, but some build problems in eclipse can be solved by deleting errors. Just go to problems view of eclipse, select error and press delete on your keyboard. Then clean project again and build it.

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