错误:无法打开类文件 R.java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3796490/
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
Error: Unable to open class file R.java
提问by Croydon Dias
Did a fresh install of Eclipse, JDK and android-sdk.
重新安装了 Eclipse、JDK 和 android-sdk。
I am currently receiving this error when creating a new project
我目前在创建新项目时收到此错误
[2010-09-26 16:07:56 - Test] ERROR: Unable to open class file C:\workspace\Test\gen\com\example\test\R.java: No such file or directory
[2010-09-26 16:07:56 - 测试] 错误:无法打开类文件 C:\workspace\Test\gen\com\example\test\R.java:没有这样的文件或目录
What's the reason for this and how do I fix it?
这是什么原因,我该如何解决?
Eclipse Helios 32 bit
java version "1.6.0_21"
Android sdk API 8
P.S. I'm new to Android development.
PS我是Android开发的新手。
EDIT: I tried most of your solutions, but nothing worked. So I started using my friend's install of Eclipse Ganymede.
编辑:我尝试了您的大部分解决方案,但没有任何效果。所以我开始使用我朋友安装的 Eclipse Ganymede。
回答by Upvote
Have a look at your console. It is an aapt abortederror. Since aapt is the tool that auto-generates R.java, therefore, R.java was not getting generated.
看看你的控制台。这是一个aapt 中止错误。由于 aapt 是自动生成 R.java 的工具,因此,没有生成 R.java。
Since R.java is a auto-generated file that stores information about your drawables you should rebuild your project. Before that have a look at your layout xml files and check them for errors.
由于 R.java 是一个自动生成的文件,用于存储有关您的可绘制对象的信息,因此您应该重建您的项目。在此之前,请查看您的布局 xml 文件并检查它们是否有错误。
Notice that Project -> Build All should be selected. Also try to run your project.
请注意,应选择 Project -> Build All。也尝试运行您的项目。
回答by Chris Huang-Leaver
Had a almost identical issue with Eclipse Helios 64 bit on Linux, but I had the "1.6.0" API selected like you. The bizarre thing was I could type;
在 Linux 上使用 Eclipse Helios 64 位时遇到了几乎相同的问题,但我像您一样选择了“1.6.0”API。奇怪的是我可以打字。
cat <the path it was moaning about>
in a console it would display correctly.
在控制台中它会正确显示。
I created a new AVD which used Android 2.1, the issue magically vanished. Perhaps it's a bug in Android SDK or Eclipse?
我创建了一个使用 Android 2.1 的新 AVD,这个问题神奇地消失了。也许这是 Android SDK 或 Eclipse 中的错误?
回答by Ency
I have had same issue, all what I needed to do, was create project and restart eclipse.
我遇到了同样的问题,我需要做的就是创建项目并重新启动 eclipse。
//Edit: Complete collapsing of "Package" tree works as well.
//编辑:“包”树的完全折叠也有效。
回答by James andresakis
I had a similar error on the creation of new projects myself. After messing around I tried moving the R.Java file into the same location as my projects java file (the src file). Eclipse then saw I removed the R.Java file from its location and created another and that seemed to clean up the error.....I dont know if it was because eclipse rebuilt the file and then saw it or what but that seemed to work for now.
我自己在创建新项目时也有类似的错误。在搞乱之后,我尝试将 R.Java 文件移动到与我的项目 java 文件(src 文件)相同的位置。Eclipse 然后看到我从它的位置删除了 R.Java 文件并创建了另一个文件,这似乎清除了错误.....我不知道是不是因为 Eclipse 重建了文件然后看到了它或什么但似乎现在工作。
回答by iko
I would say that once you have created your project and you've mention the R.class error --> just restart the Eclipse IDE and everything will be fine ;)
我想说的是,一旦你创建了你的项目并且你提到了 R.class 错误——> 只需重新启动 Eclipse IDE,一切都会好起来的 ;)
回答by guldari
Right click on your project name in package explorer. Then click 'Validate'. It will be fine.
在包资源管理器中右键单击您的项目名称。然后单击“验证”。没事的。
回答by Orlando Herrera
1.-Open Eclipse 2.-Open Window/Preference 3.-Expand JAVA option 4.-Select Build Path 5.-Check the option "Projec"t and uncheck "folder" options 6.-Click on OK 7.-Restart eclipse IDE
1.-打开 Eclipse 2.-打开窗口/首选项 3.-扩展 JAVA 选项 4.-选择构建路径 5.-选中“项目”选项并取消选中“文件夹”选项 6.-单击确定 7.-重新启动日食IDE
Let's go to code !!
让我们上代码吧!!
回答by Brennan McEachran
Here is how to fix it: Go to your "workspace" folder and make sure it's not "read-only"
以下是修复它的方法:转到您的“工作区”文件夹并确保它不是“只读”
回答by Sam Bartle
This is a mighty annoying error.
这是一个非常烦人的错误。
It happens 100% of the time when I create a new android project.
当我创建一个新的 android 项目时,它 100% 都会发生。
What seems to work for me is to just delete the file (which DOES exist and is accessible by my user), then hit build, and it will regenerate it and stop moaning.
似乎对我有用的是删除文件(它确实存在并且我的用户可以访问),然后点击构建,它会重新生成它并停止呻吟。
It's clearly a bug as there are too many people getting it simply by filling in the boxes in the new project dialog (like me) without even modifying any code!
这显然是一个错误,因为有太多人只是通过填写新项目对话框中的框(像我一样)而不修改任何代码来获得它!
回答by TRF
After creating the Project, Right click the Project Folder within the Project Explorer on the Left Tab of Eclipse.
创建项目后,右键单击 Eclipse 左侧选项卡上项目资源管理器中的项目文件夹。
Click on Source->Format.
单击源-> 格式。
The Console will say:
控制台会说:
[2010-11-24 11:57:42 - YourProject] R.java was modified manually! Reverting to generated version!
[2010-11-24 11:57:42 - YourProject] R.java 被手动修改!恢复到生成的版本!
Then you're good to go. Try running your Project and it will compile.
那你就可以走了。尝试运行您的项目,它会编译。