簡體   English   中英

如何修復Android布局中找不到資源的錯誤

[英]how to fix resource not found error in android layout

當我編寫代碼時出現此錯誤。 錯誤:

錯誤:找不到與給定名稱匹配的資源(在“提示”中,值為“ @ string / edit_message”)。

代碼是:

<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_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />
</LinearLayout>

這很容易,只需在res/values/strings.xml文件中添加如下所示的項目即可:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="edit_message">YOUR MESSAGE TEXT</string>
</resources>

android默認的字符串資源文件夾生成稱為字符串的信息,您是手動編寫XML還是生成代碼? 如果是手動,請嘗試修復它:

android:hint="@strings/edit_message"

如果在應用程序中找不到資源,則可以通過編程方式在edittext上設置提示:

editMessage.setHint("hint message"):

或者您可以簡單地在EditText上調用setHint()。

請參閱: http : //developer.android.com/reference/android/widget/TextView.html#setHint%28int%29

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM