简体   繁体   English

android java类无法识别R文件

[英]The android java class cannot recognize the R file

I had two layout files on R.java and I checked it was there on R.java(written on it). 我在R.java上有两个布局文件,我检查它是否在R.java上(写在它上面)。 But strangely the java class cannot recognize the layout and keep saying that the layout cannot be resolved. 但奇怪的是,java类无法识别布局,并一直说无法解析布局。 I Have Run the project but it keep saying that my project contains error. 我已经运行了项目,但它一直说我的项目包含错误。 Is this some kind of bugs? 这是某种错误吗?

检查是否有R导入(它不应该)删除R(它应该自己生成)清理项目运行

Check the import section of your java class. 检查java类的导入部分。 Sometimes Eclipse incorrectly imports android.R class instead of one generated in your project. 有时Eclipse错误地导入android.R类而不是项目中生成的类。

Please check the Console. 请检查控制台。 It should contain some error messages which prevent the R file from being generated. 它应包含一些错误消息,以防止生成R文件。

I had similar issue in Android Studio. 我在Android Studio中遇到了类似的问题。 A gradle build fixed the issue. gradle构建解决了这个问题。 Hope a ant/gradle rebuild of the project will fix the broken dependency. 希望项目的ant / gradle重建将修复破坏的依赖。

Make sure your XML files have no errors before using anything referenced in the R.java file. 在使用R.java文件中引用的任何内容之前,请确保您的XML文件没有错误。 R.java isn't built if there are errors in your XML files. 如果XML文件中存在错误,则不会构建R.java。

This must be for 2 reason normaly. 这必须是正常的2个原因。

You have a error in some xml of your project 您的项目的某些xml中有错误

You must to clean the proyect (project - clean - clean project) 你必须清理proyect(项目 - 清洁 - 清洁项目)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM