R.Java 未生成

发布于 2024-12-19 02:15:45 字数 268 浏览 2 评论 0 原文

我已经从 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

你的呼吸 2024-12-26 02:15:45

一般来说,要使其工作:

  1. 在 Eclipse中将项目导入 eclipse(文件 -> 导入 -> 常规 -> 现有项目到工作区)
  2. ,手动创建 gen 文件夹并将其添加为源文件夹(右键单击您的项目,构建路径 -> 配置构建路径 -> 添加文件夹)
  3. 清理你的项目,你应该生成 R.java

但它没有,为什么?

因为 res 中的 xml 文件存在一些编译错误(或 bug?),所以 R 没有生成(我在我的 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>

然后做一个 Project ->干净了,你应该生成 R.java。

据报告,在某些操作系统中无法解析parent =“android:WindowTitleBackground”的错误,请查看此处了解更多详细信息。

In general, to make it work:

  1. import project into eclipse (File -> Import -> General -> Existing Projects into Workspace)
  2. in Eclipse, Manually create gen folder and add it as source folder (right click on your project, Build Path -> Configure Build Path -> Add folder)
  3. Clean your project, you suppose to get R.java generated

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:

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

In res/values/themes.xml: comment out the following:

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

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.

德意的啸 2024-12-26 02:15:45

只要未生成生成的 R 类,就表明由于 XML 资源的某些解析问题,生成它时出现问题。检查 IDE 中的错误控制台以找出具体错误所在。

常见问题有:

  • strings.xml 中存在未转义字符,例如 youre 而不是 you\'re
  • 缺少 layout_width布局资源中的 layout_height 标签
  • 缺少名称空间声明
  • Java 不支持的变量名称,例如由于大写或使用空格、连字符或其他不支持的字符
  • 任何其他类型的语法错误于XML
  • 检查控制台是否存在问题(附有图像,其中控制台正在定义 R 未在项目中生成的问题)

在此输入图像描述

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:

  • An unescaped character in your strings.xml, for instance you're instead of you\'re
  • Missing layout_width or layout_height tags in layout resources
  • Missing namespace declarations
  • Variable names that aren't supported by Java, for instance due to capitalization or use of spaces, hyphens or other unsupported characters
  • Any other kind of syntax error in XML
  • Check Console for the Issues (Image is attached where console is defining the issue why R is not generating in your project)

enter image description here

美胚控场 2024-12-26 02:15:45

当我遇到这个问题时,我删除了 gen 文件夹,它将使用所有 r 文件重新创建

When i come across this problem I delete the gen folder and it will be recreated with all the r files

雨的味道风的声音 2024-12-26 02:15:45

你会在文件顶部看到它说 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

够运 2024-12-26 02:15:45

我在尝试构建从 code.google.com 下载的 wiktionary 示例代码时遇到了同样的问题(这里)我已经导入到一个新的 Eclipse Juno 项目中,设置为使用 Android 4.1 和 JDK 1.6。

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

W/ResourceType(6292):错误的 XML 块:标头大小 103 或总大小 0 大于数据大小 0
C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\values\strings.xml:23:错误:以非位置格式指定的多个替换;您的意思是添加 formatted="false" 属性吗?
C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\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>

解决方案

将 formatted="false" 添加到最后 3 个字符串定义(包含两个 %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>

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:

W/ResourceType( 6292): Bad XML block: header size 103 or total size 0 is larger than data size 0
C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\values\strings.xml:23: error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
C:\Development\WorkJava\android\sampleapps\Wiktionary\com.example.android.wiktionary.LookupActivity\res\values\strings.xml:23: error: Unexpected end tag string

Here's an excerpt of the 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>

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.

<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>
浅暮の光 2024-12-26 02:15:45

在检查所有资源没有错误、清理、重建、重新启动等后,我仍然遇到此错误。

我通过从项目中过滤掉 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.

梦中的蝴蝶 2024-12-26 02:15:45

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

".xml files" and "image files" and make sure that the names of the lowercase.

离笑几人歌 2024-12-26 02:15:45

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

Change the workspace to new directory and set its permissions such that it is available for everyone

围归者 2024-12-26 02:15:45

就我而言,我发现一个图像文件名在 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

归途 2024-12-26 02:15:45

我多次遇到这个问题。经验法则是检查您的 .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.

冷夜 2024-12-26 02:15:45

只需单击

Build --> Clean Project

“这对我有用”

Simply click on

Build --> Clean Project

This worked for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文