2013-01-14 31 views
0

好吧,我已經在Android開發者網站的教訓樣品之後,代碼是這樣的:構建簡單的用戶界面課樣品

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 
<EditText android:id="@+id/edit_message" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:hint="@string/edit_message" /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_send" /> 
</LinearLayout> 

顯然,代碼要細,擔心我輸入它錯後,我最終直接複製它,但控制檯告訴我:

說明 錯誤:錯誤:找不到與給定名稱匹配的資源('提示'的值爲'@ string/edit_message')。

說明 錯誤:錯誤:找不到與給定名稱匹配的資源(位於'文本',值爲'@ string/button_send')。

現在這些值在strings.xml文件中定義。所以我不知道爲什麼我會得到這些錯誤。

任何人誰可以幫助這裏是一個很大的提前感謝。

+0

您是否保存了'strings.xml',保存了佈局,然後清理了項目(如果有必要)? – Sam

回答

0

確保res中沒有任何大寫字母或下劃線。 此外,res和src文件內部不得有任何錯誤。 之後,您必須按前面的答案中所述清理項目。 實際上,這些錯誤會阻止R文件被更新,這是訪問res文件內部資源所必需的。

+0

發現困難的方式:)謝謝你告訴我爲什麼。 –

1

嘗試在eclipse項目>乾淨。有時候日食會給你這樣的錯誤。或者重新啓動eclipse。你有沒有在你的strings.xml中確認你有這樣的事情?
<string name="edit_message">Your intresting string.</string>有時如果你使用'gui資源加法器'它會給出錯誤。檢查你的XML裏面。

+0

好的嘗試:清理文件 –

+0

它是否工作?你有沒有確定你的其他xml沒有錯誤? – wtsang02

+0

哎呀抱歉,試圖編輯答案耗盡時間...好了嘗試:清理文件,重新啓動Eclipse。當我重新檢查「strings.xml」文件時,這兩個變量已經消失了!所以我把它們放回去了,錯誤消失了 - 可能是因爲我急忙忘了保存文件。雖然我知道我做到了! –