找不到与给定名称匹配的资源(在'text'处,值为'@ string/continue_label')

Ski*_*izz 11 java eclipse android

首先让我说我是Android编程的新手.我正在使用Pragmatic的Hello Android书(第3版).我正在研究流行的数独游戏示例,在复制了要放在main.xml文件中的书中的代码后,我收到以下错误:

error: Error: No resource found that matches the given name (at 'background' with value '@color/background')
.
error: Error: No resource found that matches the given name (at 'text' with value '@string/main_title').

error: Error: No resource found that matches the given name (at 'text' with value '@string/continue_label').

error: Error: No resource found that matches the given name (at 'text' with value '@string/new_game_label').

error: Error: No resource found that matches the given name (at 'text' with value '@string/about_label').

error: Error: No resource found that matches the given name (at 'text' with value '@string/exit_label').
Run Code Online (Sandbox Code Playgroud)

他们可能都是相关的,但经过一些搜索,我不知道问题是什么.有什么建议?

Ras*_*sel 8

错误说明了一切.你有一个res文件夹,你的资源就像字符串/图像/布局可以驻留.所以你引用资源但它们不存在.就像你引用about_label字符串但在你的字符串xml中没有标签string about_label及其value.See res-> strings.Check所有的xml文件,并将您尝试使用的资源放在程序中

  • 好的,我想我明白了.在仔细查看我的书后,我在"strings.xml"中遗漏了一些xml代码.之后,我不得不创建一个"colors.xml"文件,添加一些本书所要求的代码,然后将其导入到项目中.这非常有帮助.非常感谢你! (2认同)

小智 6

对于字符串错误,您必须在res/values/strings.xml文件中定义字符串,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="main_title">My Main Title</string>
</resources>
Run Code Online (Sandbox Code Playgroud)

其他错误类似.资源未在res文件夹中定义.