我已经从 google code 下载了代码,但是当我在 eclipse IDE 中导入该项目时
它不会生成 R.Java 文件。我搜索了很多博客和论坛并尝试了很多方法,例如清理、重建、从现有源创建项目等,但仍然面临问题。有人提到它有时是由 SVN 客户端软件引起的,但他们都没有提到任何解决方案。如果您自己下载并找到确切的问题是什么,我将非常感谢你们。
I have downloaded code from google codes but when I import that project in my eclipse IDE
it does not generate R.Java file.I searched many blogs and forums and tried many things like cleaning ,rebuilding, creating project from existing source etc but still facing the problem.Some people mentioned that it is sometimes caused by the SVN client software,but none of them mentioned any solution for that.I will be very thankful to you guys if you download it yourself and find what is the exact problem.
发布评论
评论(11)
一般来说,要使其工作:
但它没有,为什么?
因为 res 中的 xml 文件存在一些编译错误(或 bug?),所以 R 没有生成(我在我的 Mac 上测试过):
在 res/values/styles.xml 中:注释掉以下内容:
在 res/values/themes.xml 中:注释掉以下内容:
然后做一个 Project ->干净了,你应该生成 R.java。
据报告,在某些操作系统中无法解析parent =“android:WindowTitleBackground”的错误,请查看此处了解更多详细信息。
In general, to make it work:
But It doesn't, Why?
Because there are some compile error (or bug?) regarding to the xml file in res, so R is not genetared (I've tested on my Mac):
In res/values/styles.xml: commented out the following:
In res/values/themes.xml: comment out the following:
Then do a Project -> Clean, you should get R.java generated.
There is bug reported that parent="android:WindowTitleBackground" cannot be resolved in some operating system, check out here for more details.
只要未生成生成的 R 类,就表明由于 XML 资源的某些解析问题,生成它时出现问题。检查 IDE 中的错误控制台以找出具体错误所在。
常见问题有:
strings.xml
中存在未转义字符,例如youre
而不是you\'re
layout_width布局资源中的
或layout_height
标签Whenever your generated R class isn't generated, it indicates that there's a problem with generating it due to some parsing issue from the XML resources. Check the error console in your IDE to figure out what's specifically wrong.
Common problems are:
strings.xml
, for instanceyou're
instead ofyou\'re
layout_width
orlayout_height
tags in layout resources当我遇到这个问题时,我删除了 gen 文件夹,它将使用所有 r 文件重新创建
When i come across this problem I delete the gen folder and it will be recreated with all the r files
你会在文件顶部看到它说 import android.r 或 r.java 我忘记了。您需要删除此行,清理项目,然后重新运行。
基本上 android 使用 R 来引用项目中的项目。但是当该 import 语句存在时,它会覆盖查看您的项目目录并使用 androids
you will see at the top of your file it says import android.r or r.java i forget. you need to remove this line, clean the project, and rerun.
basically android uses R to reference items within your project. but when that import statement is there it overrides looking at your project directories and uses androids
我在尝试构建从 code.google.com 下载的 wiktionary 示例代码时遇到了同样的问题(这里)我已经导入到一个新的 Eclipse Juno 项目中,设置为使用 Android 4.1 和 JDK 1.6。
以下是构建项目后控制台的摘录:
这是 res/values/string 的摘录。 xml:
解决方案
将 formatted="false" 添加到最后 3 个字符串定义(包含两个 %s 替换占位符),如下所示,解决了 问题。重建项目在gen文件夹中生成R.java。
I encountered the same problem trying to build the wiktionary sample code I downloaded from code.google.com (here) I had imported into a new Eclipse Juno project set to use Android 4.1 and JDK 1.6.
Here is an excerpt of the console after building the project:
Here's an excerpt of the res/values/string.xml:
SOLUTION
Adding formatted="false" to the 3 last string definitions (containing two %s substitution placeholders), as shown below, solved the problem. Rebuilding the project generated R.java in the gen folder.
在检查所有资源没有错误、清理、重建、重新启动等后,我仍然遇到此错误。
我通过从项目中过滤掉 SVN 文件来修复此问题。
如何在 Eclipse 中从搜索中排除 .svn 目录?
虽然问题提到了搜索,但解决方案也涉及编译时使用的文件。
重新启动,一切都很好。
I still had this error after checking that all my resources had no errors, cleaning, rebuilding, restarting, etc.
I fixed this by filtering out the SVN files from the project.
How to exclude .svn directories from search in Eclipse?
While the question mentions search, the solution pertains to what files are used in compiling as well.
Restarted, and everything was fine.
“.xml 文件”和“图像文件”并确保名称为小写。
".xml files" and "image files" and make sure that the names of the lowercase.
将工作区更改为新目录并设置其权限,以便所有人都可以使用
Change the workspace to new directory and set its permissions such that it is available for everyone
就我而言,我发现一个图像文件名在 res/drawable 中包含大写字母。更改图像名称后。它已解决,我可以构建该项目
In my case, i found an image file name containing an uppercase inside res/drawable. after changing the image name. it was solved and i could build the project
我多次遇到这个问题。经验法则是检查您的 .xml 文件。
.xml 文件有问题时不会生成 R.java。
I faced this problem many times. The rule of thumb is to check your .xml files.
R.java is not generated when there is any issue in .xml file.
只需单击
“这对我有用”
Simply click on
This worked for me