在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文件中。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章