在 Android 上使用 eclipse 时出错 - 找不到与给定名称匹配的资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2477647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error using eclipse for Android - No resource found that matches the given name
提问by KennyH
Common problem I'm sure, but I can't figure it out. In my AndroidManifest.xml and main.xml I'm getting the no resource found that matches the given name. I've double checked for typos and it used to work, but now I'm popping up with all these errors saying it can't find my strings in my strings.xml.
我确定是常见问题,但我无法弄清楚。在我的 AndroidManifest.xml 和 main.xml 中,我没有找到与给定名称匹配的资源。我已经仔细检查了拼写错误,它曾经可以工作,但现在我弹出所有这些错误,说它在我的 strings.xml 中找不到我的字符串。
These are the ones I'm getting errors for in my main.xml.
这些是我在 main.xml 中遇到错误的那些。
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/instructions" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/level_prompt" />
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/level_array" />
These are the ones I'm getting for my androidmanifest.xml.
这些是我为我的 androidmanifest.xml 得到的。
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloFormStuff" android:label="@string/title">
This is what my strings.xml looks like.
这就是我的 strings.xml 的样子。
<string name="title">Title</string>
<string name="app_name">Application name</string>
<string name="instructions">Enter instructions here.</string>
<string name="level_prompt">Choose an item</string>
<string-array name="level_array">
<item>Item One</item>
<item>Item Two</item>
<item>Item Three</item>
<item>Item Four</item>
</string-array>
Any ideas? Any help would be appreciated!!
有任何想法吗?任何帮助,将不胜感激!!
回答by KennyH
Accidentally moved the "values" folder outside of the "res" folder. Moved it back and it fired up!
不小心将“values”文件夹移到了“res”文件夹之外。把它移回去,它开火了!
回答by Stephen Wylie
This problem appeared for me due to an error in an XML layout file. By changing @id/meid
to @+id/meid
(note the plus), I got it to work. If not, sometimes you just gotta go to Project -> Clean...
由于 XML 布局文件中的错误,我出现了这个问题。通过更改@id/meid
为@+id/meid
(注意加号),我开始工作了。如果没有,有时您只需要转到 Project -> Clean ...
回答by IgorGanapolsky
I resolved this kind of issue like this: I went into my XML layout file, cut the line of code that was generating the error. Then I saved the file, and pasted the code back in. The error was gone.
我解决了这样的问题:我进入了我的 XML 布局文件,剪切了产生错误的代码行。然后我保存了文件,并重新粘贴了代码。错误消失了。
回答by Mahesh
One general solution to such tiny errors is that you close eclipse and start is again.. 3 irritating problems were solved.. its the problem with eclipse.. some times it didn resolve "R.id", the it didn find @string/somebutton, and then again some random thing... if nothing logical comes in your mind, try this, n conjure d result.. :)
解决此类微小错误的一种通用解决方案是关闭 eclipse 并再次启动.. 3 个恼人的问题已解决.. eclipse 的问题.. 有时它没有解决“R.id”,它没有找到@string/一些按钮,然后又是一些随机的事情......如果你没有想到任何合乎逻辑的东西,试试这个,n 想出结果.. :)
回答by Sephy
I think the issue is that you have
我认为问题是你有
android:prompt="@string/level_array"
and you don't have any string with the id, to refer to the array, you need to use @array
并且您没有任何带有 id 的字符串,要引用数组,您需要使用 @array
test this or put a screen of your log please
测试这个或把你的日志屏幕
回答by ZoharAdar
tried what KennyH write but it didn't solved my problem that appear while trying edit style.xml file in my android app, so I just delete the project from eclipse (not from disk of course !!) and import it back ,solved it for me in that case.
尝试了 KennyH 写的内容,但它没有解决我在我的 android 应用程序中尝试编辑 style.xml 文件时出现的问题,所以我只是从 eclipse(当然不是从磁盘中!!)中删除该项目并将其导入回来,解决了它在那种情况下对我来说。
回答by SteJav
I renamed the file in res/values "strings.xml" to "string.xml" (no 's' on the end), cleaned and rebuilt without error.
我将 res/values 中的文件“strings.xml”重命名为“string.xml”(末尾没有“s”),清理和重建没有错误。
回答by blackHyman75
I actually has this problem once with a path issue referring another project :
我实际上曾经遇到过这个问题,因为路径问题涉及另一个项目:
I had this in my default.properties:
我在我的 default.properties 中有这个:
android.library.reference.1=..\MyProject_Core\
Which I fixed like this:
我是这样修复的:
android.library.reference.1=../MyProject_Core/
My colleague created the above with Windows but only the version below worked on my Mac.
我的同事用 Windows 创建了上面的版本,但只有下面的版本可以在我的 Mac 上运行。
回答by Aravindhan
If you are an iPhone Developer don't just add your picture (by right clicking then add file...like we do in iPhone). You have to copy and paste the picture in your drawable folder.
如果您是 iPhone 开发人员,请不要只添加图片(通过右键单击然后添加文件...就像我们在 iPhone 中所做的那样)。您必须将图片复制并粘贴到可绘制文件夹中。
回答by Boris Strandjev
For me the issue appeared because my string file could not be parsed. I wanted to have a value like '%s - %s'
. However this appeared to be triggering a problem, it seems string will try to parse this value in a special way. Because two string values were provided in a single value an error was written in the console, but I had so many errors triggered from that, that the initial error was hidden, because of small console buffer. Adding formatted="false"
attribute to this string value of mine fixed the problem in the string file (which btw was not reported as compilation error in the file itself) and I was able to build once more.
对我来说,出现问题是因为无法解析我的字符串文件。我想要一个像'%s - %s'
. 然而,这似乎引发了一个问题,似乎 string 会尝试以一种特殊的方式解析这个值。因为在一个值中提供了两个字符串值,所以在控制台中写入了一个错误,但是我从中触发了很多错误,由于控制台缓冲区很小,所以隐藏了初始错误。向formatted="false"
我的这个字符串值添加属性修复了字符串文件中的问题(顺便说一句,文件本身没有报告为编译错误),我能够再次构建。