eclipse 没有生成 R 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3462609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:59:11  来源:igfitidea点击:

No R class is generated

androideclipse

提问by lgwest

The automatic generation of the R class does not work anymore. I have tried Project -> Clean... A warning on all xml files has also showed up: “No grammar constraints (DTD or XML schema) detected for the document.” Maybe that is why the code generation have stoped. Any idea how to get the R class generated again?

R 类的自动生成不再起作用。我试过 Project -> Clean... 所有 xml 文件上的警告也出现了:“没有检测到文档的语法约束(DTD 或 XML 模式)。” 也许这就是代码生成停止的原因。知道如何再次生成 R 类吗?

回答by Macarse

The R file will not be generated unless there are not error in the /res/folder.

除非/res/文件夹中没有错误,否则不会生成 R 文件。

If there are not errors in the /res/folder, try removing the gen folder and then right click on the project -> android -> fix android settings.

如果/res/文件夹中没有错误,请尝试删除 gen 文件夹,然后右键单击项目 -> android -> 修复 android 设置。

回答by HymanKnifeZero

As the other posts say, the /res folder mustn't have any files that have errors in them. If so then the R.class file cannot be generated. If the errors are fixed then the project should re-build and the R.class should generate. If not, I believe you can right-click on the project then Android Tools -> Fix Project Properties. I think that is what @Macarse was meaning by project -> android -> fix android settings. I didn't see those options but the Android Tools -> Fix Project Properties usually does the trick for me or sometimes cleaning the source works too (Right-click the project -> Source -> Clean up...).

正如其他帖子所说, /res 文件夹中不能有任何有错误的文件。如果是,则无法生成 R.class 文件。如果错误已修复,则应重新构建项目并生成 R.class。如果没有,我相信您可以右键单击该项目,然后单击“Android 工具”->“修复项目属性”。我认为这就是@Macarse 所指的项目 -> android -> 修复 android 设置。我没有看到这些选项,但 Android 工具 -> 修复项目属性通常对我有用,有时也可以清理源代码(右键单击项目 -> 源代码 -> 清理...)。

Hope this helps you.

希望这对你有帮助。

:)

:)

Hyman

Hyman

回答by Sephy

Generally when you get this kind of error, that means that you have an error in one of your resources. Have you added a drawable, changed a layout, or added/modified any resource just before this happens?
For instance if you created a 9-patch drawable, you can't have the image.png and image.9.png at the same time in the drawable folder, it will create an error, and Eclipse will go crazy. Same thing If you made a mistake in a xml file, and saved it. Then the R class can't be generated as long as you have not corrected the file.

通常,当您遇到此类错误时,这意味着您的资源之一存在错误。在这种情况发生之前,您是否添加了可绘制对象、更改了布局或添加/修改了任何资源?
例如,如果你创建了一个 9-patch drawable,你不能在 drawable 文件夹中同时拥有 image.png 和 image.9.png,这会产生一个错误,Eclipse 会发疯。同样的事情如果您在 xml 文件中犯了错误,并保存了它。那么R类只要你没有更正文件就无法生成。

回答by AndroidBeginer

In my case it was so simple as defining the sdk location ending with a slash. The problem was that it wasn't finding appt.exe because it was looking for it in ../sdkplatform-tools/aapt.exe instead in ../sdk/platform-tools/aapt.exe

在我的情况下,它就像定义以斜杠结尾的 sdk 位置一样简单。问题是它没有找到 appt.exe,因为它在 ../sdkplatform-tools/aapt.exe 中寻找它,而不是在 ../sdk/platform-tools/aapt.exe

回答by Burhan ARAS

Here is your solution:

这是您的解决方案:

Open a terminal window and type

打开终端窗口并输入

sudo apt-get install ia32-libs

须藤 apt-get 安装 ia32-libs

even if you are using a 64-bit os, this will again help you. It worked perfectly for me.

即使您使用的是 64 位操作系统,这也会再次帮助您。它非常适合我。

回答by Pavel Alexeev

I use Intellij IDEAand some day R class stopped generating (maybe, after update).

我使用Intellij IDEA,有一天 R 类停止生成(也许,更新后)。

Setting “External build” checkmark in compiler preferences fixes the problem:

在编译器首选项中设置“外部构建”复选标记修复了问题:

enter image description here

在此处输入图片说明

回答by fer

I have the answer, in my case where my R class could not be detected by the src class. Just make sure that the name of the package where the R class is located (appname -> gen-> package-> R.class Is the samethan the one you are actually using in your src Activity class.

我有答案,在我的 R 类无法被 src 类检测到的情况下。只需确保 R 类所在的包的名称(appname -> gen-> package-> R.class您在 src Activity 类中实际使用的名称相同

回答by James Moore

While it's true that R won't be generated if there are errors in your resources, I've found that the problem is that Eclipse doesn't always report errors.

如果您的资源中存在错误,确实不会生成 R,但我发现问题在于 Eclipse 并不总是报告错误。

Do this in your project directory:

在您的项目目录中执行此操作:

android update project -p .

and then build from the command line. See if that comes up with any useful errors.

然后从命令行构建。看看是否会出现任何有用的错误。

回答by Stenofh

Also this can happen because of one of the folders are named wrong, and so compromising the android directory structure. In my case, I tried to generate the class R in many ways I saw here until I realized I had created a folder "res / drawble" instead of "res / drawable". Like magic, you just go to Project-> Clean with "Build Automatically" checked and it appeared.

这也可能是因为其中一个文件夹命名错误,从而影响了 android 目录结构。就我而言,我尝试以我在这里看到的多种方式生成类 R,直到我意识到我创建了一个文件夹“res/drawble”而不是“res/drawable”。就像魔术一样,您只需转到 Project-> Clean 并选中“Build Automatically”,它就会出现。