在Eclipse中为Android开发:R.java无法重新生成

本文翻译自:Developing for Android in Eclipse: R.java not regenerating

I've found out that my R.java is never updated, so it doesn't contain information about my new resources, so I decided to delete it and thought that Eclipse would generate a new one. 我发现我的R.java从未更新过,因此它不包含有关新资源的信息,因此我决定删除它,并认为Eclipse会生成一个新资源。 But that didn't happen, and I don't have R.java now. 但这没有发生,而且我现在没有R.java。 How can I regenerate one? 如何重新生成一个?

I'm using Windows 7. 我正在使用Windows 7。

From one of the comments: "Doing Project -> Clean is what caused the problem for me. Cleaning deletes R.java...and for whatever reason the plugin is not regenerating the file." 从其中一项评论中:“执行项目 -> 清理是造成我问题的原因。清理会删除R.java ...,并且无论出于何种原因,插件都不会重新生成文件。”


#1楼

参考:https://stackoom.com/question/BZFT/在Eclipse中为Android开发-R-java无法重新生成


#2楼

Make sure you are not importing 确保您没有导入

android.R; android.R;


#3楼

R.java will never be generated if there are any errors in the res folder. 如果res文件夹中有任何错误,将永远不会生成R.java。 For example, in the drawable subfolder there are two files which have the same name, one is icon.png and the other is icon.html. 例如,在drawable子文件夹中,有两个文件具有相同的名称,一个是icon.png,另一个是icon.html。

You can see some error in the Eclipse console log window which is saying "Resource entry icon is already defined.". 您会在Eclipse控制台日志窗口中看到一些错误,说“资源条目图标已定义”。 After deleting icon.html, you can clean or just delete the gen folder. 删除icon.html之后,您可以清理或仅删除gen文件夹。 You will find that R.java is created. 您会发现R.java已创建。


#4楼

After reading through many posts and YouTube videos, I found that each of us have R.java missing for different reasons. 阅读了许多帖子和YouTube视频之后,我发现我们每个人都有R.java缺失的原因不同。

Here's how I fixed this in Eclipse: 这是我在Eclipse中解决此问题的方法:

  • Create R.java in gen folder manually and save. gen文件夹中手动创建R.java并保存。
  • After that go to Project and click "Clean" 之后,转到Project并单击“清理”

The following message will display and your file will automatically be rewritten: 将显示以下消息,并且您的文件将自动被重写:

R.java was modified manually! R.java是手动修改的! Reverting to generated version! 恢复到生成的版本!


#5楼

I had this problem. 我有这个问题。 Accidentally I deleted this 我不小心删除了这个

xmlns:tools="http://schemas.android.com/tools"

which started causing build errors all over the project in my XML files as well as my Java files. 这开始在我的XML文件和Java文件中的整个项目中引起构建错误。 As soon as I retyped what I deleted, it worked again :) 当我重新输入删除的内容后,它再次起作用:)


#6楼

I've found that any file that has capital letters in the res folder will create this error. 我发现任何res文件夹中具有大写字母的文件都会产生此错误。 This happened to me with a PNG file I added and forgot about. 这发生在我添加并忘记的PNG文件中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值