R.java文件没有生成?
我正在开发一个运行良好的应用程序。
我尝试了一些新的布局文件,但是当我构建项目时,未生成 R.java 文件。 我尝试清理并构建项目,但仍然没有生成文件。
为什么会发生这种情况?
我现在应该做什么来重新生成文件?
I am working on an app which was working fine .
I tried some new layout files but when I build the project the R.java file is not generated .
I tried clean and build project but still the file is not generated.
Why is this happening?
What should I do now to regenrate the files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果任何 XML 文件中有错误,Android 在清理后将不会生成 R.java。检查是否有任何错误并修复它们。然后将构建 R.java。
如果这不起作用,有时 Eclipse 会丢失该文件的跟踪。单击您的项目并按 F5 刷新项目。
Android will not generate the R.java after a clean if any of the XML files have errors in them. Check for any errors and fix them. R.java will then be built.
If that doesn't work, sometimes Eclipse looses track of the file. Click your project and hit F5 to Refresh the project.
R.java 文件在应用程序中自动生成。如果您想知道为什么没有生成 R.java 文件,那么您制作的最后一个布局文件存在一些问题。
如果根据 android 存在非法或 XML 文件中有任何错误,则 R.java 文件将被删除。
谢谢。
R.java file is automatically generated in application. If you want to know why your R.java file is not generated then there are some problem into your last layout file made by you.
If there is illegal according to android OR if there is any error in XML file then R.java file will be deleted.
Thanks.
尝试刷新您的项目。右键单击项目资源管理器中的项目文件夹,然后单击刷新选项
Try refreshing your project. Right click on your project folder in the project explorer, and click on the Refresh option
根据我的经验,Eclipse ADT 不会在包窗口中显示所有错误,例如亚洲字符文件名和 Windows 中的系统配置文件。有时,您必须在检查并删除这些文件后重新导入项目。
In my experiences, Eclipse ADT will not show every errors in package window, e.g. Asia characters file names, and system-config-file from Windows. Sometimes, you have to re-import your project after check and remove these files.
我尝试了以下方法。将应用程序名称视为“我的第一个应用程序”。那么包的名称应该是com.xx.myfirstapplication.yy。创建应用程序时,请确保在程序包字段中的应用程序名称后面添加 yy。希望有帮助。
I tried the following. Consider the application name to be "My First Application". Then the name of the package should be com.xx.myfirstapplication.yy. Make sure that you add a yy after the application name in the package field while creating the application. Hope it helps.
检查菜单文件夹中是否有 main.xml 文件,但 strings.xml 中没有 有时
这就是我的情况的原因。
Check if you have main.xml file in the menu folder, but don't have in strings.xml
Sometimes that is the reason in my case.
所以我意识到这个问题已经有了答案。然而,我今天遇到了完全相同的问题,并且被困了大约一个小时。我想出了一个不同的解决方案来解决我的问题。 XML 中没有任何错误/拼写错误。
我试图让 Google 钱包示例运行。
我的解决方案最终是 android:minSdkVersion (在清单文件中)设置得太低。我只是提高了这个值,所有错误都消失了。
So I realize this question has already been answered. However, I had the exact same problem today and was stuck on it for about an hour. I have come up with a different solution that solved my problem. The XML did not have any errors/typos in them.
I was trying to get the Google Wallet example to run.
My solution ended up being that the android:minSdkVersion (in the manifest file) was set too low. I simply raised this value and all errors were gone.