我从中下载了代码 Google代码 但是,当我在Eclipse IDE中导入该项目时,它不会生成r.java文件。我搜索了许多博客和论坛,并尝试了许多事情,例如清洁,重建,从现有来源创建项目等,但仍然面临问题。有些人提到,有时是由SVN客户端软件引起的,但他们都没有提到任何解决方案。如果您自己下载并找到确切的问题,我将非常感谢你们。

有帮助吗?

解决方案

通常,使它起作用:

  1. 将项目导入Eclipse(文件 - >导入 - >常规 - >现有项目中的项目)
  2. 在Eclipse中,手动创建Gen文件夹并将其添加为源文件夹(右键单击您的项目,构建路径 - >配置构建路径 - >添加文件夹)
  3. 清洁您的项目,您想生成R.Java

但这不是,为什么?

因为Res中的XML文件有一些编译错误(或错误?),因此R不是Genetared(我已经在Mac上测试了):
在res/values/styles.xml中:评论以下内容:

<style name="iWindowTitleBackground" parent="android:WindowTitleBackground">    
  <item name="android:background">@drawable/title_bar</item>        
</style>

在res/values/themes.xml中:评论以下内容:

<item name="android:windowTitleBackgroundStyle">@style/iWindowTitleBackground</item>

然后进行一个项目 - >清洁,您应该生成r.java。

有错误报道,parent =“ android:windowtitlebackground”无法在某些操作系统中解决,请查看 这里 更多细节。

其他提示

每当您生成的R类未生成时,就表明由于XML资源的某些解析问题而生成的问题。检查您的IDE中的错误控制台,以找出具体错误的问题。

常见问题是:

  • 你的一个未塑造的角色 strings.xml, , 例如 you're 代替 you\'re
  • 失踪 layout_width 或者 layout_height 布局资源中的标签
  • 缺少名称空间声明
  • Java不支持的可变名称,例如由于大写或使用空间,连字符或其他不支持的字符
  • XML中的任何其他类型的语法错误
  • 查看 安慰 对于问题(附加了图像,控制台正在定义问题为什么R在项目中没有生成的问题)

enter image description here

当我遇到这个问题时,我将删除Gen文件夹,并将其重新创建所有R文件

您会在文件的顶部看到Import android.r或R.Java,我忘记了。您需要删除此行,清洁项目并重新运行。
基本上,Android使用R来参考项目中的项目。但是,当该导入语句存在时,它覆盖了您的项目目录和使用Android

我遇到了同样的问题,试图构建我从code.google.com下载的wiktionary示例代码(这里)我已经进口到一个新的Eclipse Juno项目中,该项目将使用Android 4.1和JDK 1.6。

这是构建项目后的控制台的摘录:

W/ResourceType( 6292): Bad XML block: header size 103 or total size 0 is larger than data size 0 C:DevelopmentWorkJavaandroidsampleappsWiktionarycom.example.android.wiktionary.LookupActivityresvalues strings.xml:23:错误:以非定点格式指定的多个替换;您的意思是添加格式=“ false”属性? c: development workjava android sampleapps wiktionary com.example.android.wiktionary.wiktionary.lookupactivity res res values values strings.xml:23:错误:出乎意料的结束标签字符串

这是res/values/string.xml的摘录:

<resources>

<string name="app_name">Wiktionary Word of the Day</string>
<string name="app_descrip">A fast Wiktionary browser and Word-of-day widget</string>
<string name="app_credits">"All dictionary content provided by Wiktionary under a GFDL license.  http://en.wiktionary.org\n\nIcon derived from Tango Desktop Project under a public domain license.  http://tango.freedesktop.org".</string>
<string name="template_user_agent">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title">"Wiktionary:Word of the day/%s %s"</string>
<string name="template_wotd_archive_title">"Wiktionary:Word_of_the_day/Archive/%s/%s"</string>

解决方案

如下所示,将格式化=“ false”添加到最后3个字符串定义(包含两个%s替代者)(包含两个%s替代者),这解决了问题。重建项目在Gen文件夹中生成R.Java。

<resources>

<string name="app_name">Wiktionary Word of the Day</string>
<string name="app_descrip">A fast Wiktionary browser and Word-of-day widget</string>
<string name="app_credits">"All dictionary content provided by Wiktionary under a GFDL license.  http://en.wiktionary.org\n\nIcon derived from Tango Desktop Project under a public domain license.  http://tango.freedesktop.org".</string>
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title" formatted="false">"Wiktionary:Word of the day/%s %s"</string>
<string name="template_wotd_archive_title" formatted="false">"Wiktionary:Word_of_the_day/Archive/%s/%s"</string>

在检查我所有的资源是否没有错误,清洁,重建,重新启动等之后,我仍然遇到了这个错误。

我通过从项目中滤除SVN文件来解决此问题。

如何将.SVN目录排除在Eclipse中的搜索中?

当问题提到搜索时,解决方案也与编译中使用了哪些文件有关。

重新启动,一切都很好。

“ .xml文件”和“图像文件”,并确保小写的名称。

将工作区更改为新目录并设置其权限,以便每个人都可以使用

就我而言,我找到了一个图像文件名,其中包含Res/Drawble内部的大写。更改图像名称后。它解决了,我可以建立该项目

我多次面对这个问题。经验法则是检查您的.xml文件。
.xml文件中有任何问题时,不会生成r.java。

只需单击

Build --> Clean Project

这对我有用

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top