Android Studio无法找到具有给定名称的资源

时间:2014-02-15 22:18:29

标签: android

我正在使用Android Studios教程制作我的第一个应用程序,每次尝试制作时都会出现此错误。错误是找不到与给定名称匹配的资源(在'提示'处,值为'@ string / edit_message')。这是我的代码。在一个xml文件中。

<    ?xml version="1.0" encoding="utf-8"?   >

<    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>

然后在另一个xml文件中我有这个。

<  ?xml version="1.0" encoding="utf-8"?>

<  resources>

    < string name="app_name">My first app second try</string>

    < string name="hello_world">Hello world!</string>

    < string name="action_settings">Settings</string>


    < resources>
        < string name="app_name">My First App</string>

        < string name=**"edit_message">Enter a message</string>**

        < string name=**"button_send">Send</string>**

        < string name="action_settings">Settings</string>

        < string name="title_activity_main">MainActivity</string>

    </resources>

</resources>

2 个答案:

答案 0 :(得分:0)

string.xml作为此内容,删除第二个resources代码:

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="app_name">My first app second try</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="app_name_2">My First App</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="title_activity_main">MainActivity</string>

</resources>

如果您阅读String Resources安卓文档,您将获得全部要点。

答案 1 :(得分:0)

你有两个开放的<resources>标签。删除内部标签。

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="app_name">My first app second try</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="app_name">My First App</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

</resources>