Android Error: Unable to open class file R.java
当import导入新的程序,难免会有错误爆出,其中一种错误就是程序上有个大大的红叉。但是里面并没有错误。控制台提示错误如下
问题:Error: Unable to open class file R.java No such file or directory
网上找的两个方法。貌似是第二种的成功率较高,第一种低一点。不过不一定,各位试一下吧。
第一种: The “Build Path” for your Java environment is not setup correctly in Eclipse. To fix this, follow these steps:
-
Open the Preferences Window by clicking “Window -> Preferences”
-
Find the “Java” section and expand it
-
Select “Build Path”
-
Change the value of Source and output folder from Folders to “Project”
-
Click Apply and then “OK”
Your problem should be resolved
第二种:
1.先检查你的代码,代码有误,R.java文件是生成不了的(一般导入的程序是不会有这个问题的) 2. 打开Project ----> Build Automatically那个选项勾上,让工程每次修改完后都会自动编译,这样R.java会是最新的(这时候程序有误,不会生成) 3. Project ---> Clean,点开后,选中你的工程,然后OK,(clean本身就会Reset你的工程设置,并且在之后能自动重新Build一下,如果一次clean还是有问题,那就再clean。一般两次就可以了)。这样三步下来,就能搞定你的问题了。