2011-11-29 74 views
8

我已經從google codes下載了代碼,但是當我在我的eclipse IDE 中導入該項目時,它不生成R.Java文件。我搜索了許多博客和論壇,並嘗試了許多事情,如清理,重建,創建來自現有源的項目等,但仍然面臨問題。有些人提到它有時是由SVN客戶端軟件引起的,但沒有一個提到任何解決方案。我會非常感謝你們,如果你自己下載它並找到什麼是確切的問題。R.Java not generated

+0

你試過刪除 「根」 文件夾? – vanleeuwenbram

+1

根本沒有「gen」文件夾 – Waseem

+0

對此有何更新?問題是否解決? –

回答

16

一般來說,使其工作:

  1. 導入項目到Eclipse(文件 - >導入 - >常規 - >現有項目到工作區)
  2. 在Eclipse中,手動創建gen文件夾並將其添加爲源文件夾(右鍵單擊您的項目,Build Path - > Configure Build Path - > Add folder)
  3. 清理您的項目, R.java生成

但它沒有,爲什麼?

因爲有一些編譯錯誤(?或缺陷)關於對資源的XML文件,所以R不是genetared(我在我的Mac測試):
在RES /價值/ styles.xml:評論了以下工作:

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

在RES /價值/的themes.xml:註釋掉以下內容:

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

然後做一個項目 - >乾淨,你應該得到R.java產生。

有bug報告說parent =「android:WindowTitleBackground」在某些操作系統下無法解析,請查看here瞭解更多詳情。

+5

我忘了雅,它不會產生,如果有錯誤。當我處理它時,整個R.java事情是屁股疼痛和一個愚蠢的問題。它不是真的開發商故障只是一個錯誤在SDK :( –

+0

謝謝。我沒有相同的確切的XML內容,但清理它們仍然工作。 –

1

當我遇到這個問題,我刪除根文件夾,它會與所有的R文件

+0

正如我在下面所述。這就是爲什麼當你做findById並開始輸入r.id時,你會看到android.r和r。而你的項目文件在第二個變量R中,僅供將來參考。 –

1

,你會在你的文件的頂部看到它說進口android.r或r.java我忘記重新創建。您需要刪除此行,清理項目並重新運行。
基本上android使用R引用項目中的項目。但是當import語句是有它覆蓋在看你的項目目錄,並使用機器人

1

我嘗試構建從code.google.com下載的wiktionary示例代碼(here)時遇到了同樣的問題我導入了一個新的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:\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

這裏的RES /價值/ 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

如下所示,向最後3個字符串定義(包含兩個%s替換佔位符)添加formatted =「false」,解決了該問題。重建項目在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> 
1

檢查我所有的資源沒有錯誤,清洗,改造,重新啓動等

我從項目篩選出SVN文件解決了這個後,我仍然有這個錯誤。

How to exclude .svn directories from search in Eclipse?

雖然問題提到搜索,該解決方案涉及到哪些文件編制以及使用。

重新啓動,一切都很好。

0

更改工作區以新的目錄,並設置其權限,使得它爲大家提供

1

「.xml文件」和‘圖像文件’,並確保小寫的名字。

0

在我的情況下,我發現一個圖像文件名稱包含res/drawable中的大寫字母。更改圖像名稱後。它已經解決了,我可以構建項目

3

只要您生成的R類沒有生成,就表明由於XML資源的某些解析問題而生成它時出現問題。檢查IDE中的錯誤控制檯,找出具體的錯誤。

常見的問題有:

  • 的轉義字符在strings.xml,例如you're,而不是you\'re
  • 缺少layout_widthlayout_height標籤佈局資源
  • 缺少命名空間聲明
  • 變量名不受Java支持,例如由於大寫或使用空格,連字符或其他不受支持的字符
  • 在XML的任何其他類型的語法錯誤的
  • 檢查控制檯的問題(圖像附加其中控制檯確定爲什麼R不是在你的項目中產生的問題)

enter image description here

0

我多次遇到這個問題。經驗法則是檢查你的.xml文件。
當.xml文件中存在任何問題時,不生成R.java。

0

只需點擊

Build --> Clean Project 

這爲我工作