开发者

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

开发者 https://www.devze.com 2023-03-22 12:34 出处:网络
Let me start off by saying I\'m brand new to Android programming.I\'m using a Pragmatic\'s Hello Android book (3rd edition).I\'m working on the popular sudoku game example, and after copying the code

Let me start off by saying I'm brand new to Android programming. I'm using a Pragmatic's Hello Android book (3rd edition). I'm working on the popular sudoku game example, and after copying the code from the book that is to be placed in the main.xml file, I get the following errors:

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 nam开发者_运维技巧e (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').

They're probably all related, but after doing some searching, I don't know what the problem is. Any suggestions?


Error says everything.You have a res folder where your resource like string/image/layout can reside.So you are referencing the resource but they are not present.Like you are referencing about_label string but in your string xml there is no tag for the string about_label and its value.See res->strings.Check all your xml file and put the resource you are trying to use in your program


For the string errors, you have to define your strings in the res/values/strings.xml file like this:

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

The other errors are similar. The resources aren't defined in the res folder.


Those resources are created in res/values/* folder (res/values/strings.xml or res/values/colors.xml etc...). This allows you to use on string or color over and over again.

For now, you can replace these resources with actual String objects or literals, i.e. R.string.exit_label would be replaced with "Exit".

0

精彩评论

暂无评论...
验证码 换一张
取 消