Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未找到与给定名称匹配的资源(位于';文本';处,值为';@string/hello';)_Android - Fatal编程技术网

Android 未找到与给定名称匹配的资源(位于';文本';处,值为';@string/hello';)

Android 未找到与给定名称匹配的资源(位于';文本';处,值为';@string/hello';),android,Android,我正在尝试制作一个Hello World应用程序。这里是链接到 我已经成功地完成了“用代码创建用户界面”,并在模拟器中看到了应用程序的工作,但是当我开始“创建字符串资源”时,我遇到了一些麻烦。我将Strings.xml文件更改为: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="helloButtonText">Say Hello</stri

我正在尝试制作一个Hello World应用程序。这里是链接到

我已经成功地完成了“用代码创建用户界面”,并在模拟器中看到了应用程序的工作,但是当我开始“创建字符串资源”时,我遇到了一些麻烦。我将Strings.xml文件更改为:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="helloButtonText">Say Hello</string>
        <string name="helloLabelText">Hello Mono for Android</string>
    </resources> 
}

然后,当我尝试运行时,我得到错误: 未找到与给定名称匹配的资源(位于值为“@string/hello”的“text”) 它说它在Main.axml的第2行,下面是代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
    android:id="@+id/myButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
</LinearLayout>

我尝试过其他Android教程,但我似乎总是停留在向Strings.xml文件添加内容的部分。如能解决此问题,我将不胜感激

您的问题是它(hello字符串)不存在。您创建了
hellobuttonext
helloLabelText
,但没有创建
hello

将您的按钮xml更改为此,它应该可以工作:

<Button 
    android:id="@+id/myButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/helloButtonText" /> 


或者,由于您似乎是以编程方式而不是通过您定义的XML来设置视图,因此现在可以完全删除XML布局文件。您似乎没有在任何地方使用它。

欢迎使用SO。如果以下答案之一解决了您的问题,您应该接受它(单击相应答案旁边的复选标记)。这有两件事。它让每个人都知道你的问题已经解决了,并且它给了帮助你的人信用。谢谢你的帮助。这种改变很有道理。谢谢你的帮助。我似乎无法将两个答案都标记为解决方案,但您的答案与Eldarerat相同,因此您的解决方案有效。这很好。我只是想确定你知道接受答案。很多。新的。人。不要,最终人们不会帮助他们。因为他们不接受。给出的答案。
<Button 
    android:id="@+id/myButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/helloButtonText" /> 
<Button
    android:id="@+id/myButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
<Button
    android:id="@+id/myButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/helloButtonText" />