【问题标题】:No resource found that matches the given name (at 'text' with value '@string/continue_label')未找到与给定名称匹配的资源(在“文本”处,值为“@string/continue_label”)
【发布时间】:2011-07-22 16:37:52
【问题描述】:

首先让我说我是 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').

它们可能都是相关的,但经过一番搜索,我不知道问题是什么。有什么建议吗?

【问题讨论】:

  • 从 res 目录的 Values 文件夹中发布您的 strings.xml 和 colors.xml 文件。您的资源文件夹中的某些内容可能已损坏
  • 你把值放到xml文件里了吗?

标签: java android eclipse


【解决方案1】:

错误说明一切。您有一个 res 文件夹,您的资源(如字符串/图像/布局)可以驻留。所以您正在引用该资源,但它们不存在。就像您引用 about_label 字符串一样,但在您的字符串 xml 中没有字符串 about_label 及其值的标记。请参阅 res->strings。检查所有 xml 文件并将您尝试使用的资源放入程序中

【讨论】:

  • 好的,我想我明白了。仔细查看我的书后,我在“strings.xml”中丢失了一些 xml 代码。之后,我必须创建一个“colors.xml”文件,添加一些本书要求的代码,然后将其导入项目中。这很有帮助。非常感谢!
【解决方案2】:

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="main_title">My Main Title</string>
</resources>

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

【讨论】:

    【解决方案3】:

    这些资源在 res/values/* 文件夹中创建(res/values/strings.xml 或 res/values/colors.xml 等...)。 这使您可以一遍又一遍地使用字符串或颜色。

    目前,您可以将这些资源替换为实际的 String 对象或文字,即 R.string.exit_label 将替换为“Exit”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 2018-08-16
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多