Android 错误:找不到与给定名称匹配的资源(在值为“@drawable/icon”的“icon”处)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23796414/
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 : No resource found that matches the given name (at 'icon' with value '@drawable/icon')
提问by PositivityRiven
Error : No resource found that matches the given name (at 'icon' with value '@drawable/icon').
错误:找不到与给定名称匹配的资源(在值为“@drawable/icon”的“icon”处)。
This is my manifest... I'm extremely new to this, just started this morning and have no previous programming experience.
这是我的清单......我对此非常陌生,今天早上刚开始,以前没有编程经验。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.asdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="ExampleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
回答by pperrin
Found this question. I was importing an old project into android studio and got the error.
发现这个问题。我正在将一个旧项目导入 android studio 并出现错误。
The issue was eventually answered for me here mipmap drawables for icons
这个问题最终在这里为我解答了mipmap drawables for icons
In the manifest it has
在清单中它有
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
...
but @drawable has been superseded by @mipmap so needed changing to:
但@drawable 已被@mipmap 取代,因此需要更改为:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
...
I put this answer here, as it may become a more common issue.
我把这个答案放在这里,因为它可能成为一个更常见的问题。
回答by Kristaps Folkmanis
What solved the problem for me was - create a folder "drawable" in "..platforms/android/res/" and put "icon.png" in it.
对我来说解决问题的是 - 在“..platforms/android/res/”中创建一个“drawable”文件夹并将“icon.png”放入其中。
回答by George Fonseca
If you are 100% sure that directories and files are ok, have a look at the project location.
如果您 100% 确定目录和文件没有问题,请查看项目位置。
There is a limit on the path length of files in the Operating System. Perhaps this limit is being exceded in your project files.
操作系统中文件的路径长度是有限制的。也许您的项目文件超出了这个限制。
Move the project to a shorter folder (say C:/MyProject) and try again!
将项目移至较短的文件夹(例如 C:/MyProject)并重试!
This was the problem for me!
这对我来说是个问题!
回答by anil
I've spent on this problem much time and as for me (for Intellij IDEA) the solution is to specify right path to res directory:
我在这个问题上花了很多时间,对于我(对于 Intellij IDEA),解决方案是指定 res 目录的正确路径:
- right click on project
- click Modules in the left panel
- select Android below your project name
- in Structure tab set right path.
- 右键单击项目
- 单击左侧面板中的模块
- 在您的项目名称下方选择 Android
- 在结构选项卡中设置正确的路径。
And don't forget to check all the paths in this tab!
并且不要忘记检查此选项卡中的所有路径!
I hope it will be helpful for somebody!
我希望它会对某人有所帮助!
回答by Illegal Argument
Remove this line from your manifest:
从清单中删除此行:
<application android:label="@string/app_name" android:icon="@drawable/icon">
You have two application tags only one should be present.
您有两个应用程序标签,只有一个应该存在。
回答by Seyhak Ly
You need to add icon.pngthrough visual.
需要通过visual添加icon.png。
Resouces... / Dravable/ Add ///
Resouces... / Dravable/ Add ///
回答by pablo rotem
There's an even simpler solution - delete the cache folder at user/.android/built-cache and go back to android studio and sync with gradle again, if that still doesn't work delete the cache folder again, and restart android studio and re-import the project
有一个更简单的解决方案 - 删除 user/.android/built-cache 中的缓存文件夹,然后返回 android studio 并再次与 gradle 同步,如果仍然不起作用,再次删除缓存文件夹,然后重新启动 android studio 并重新- 导入项目
回答by Josh
Yet another Googlemare Landmine.... Somehow, if you mess up, the icon line on your .gen file dies. (Empirical proof of mine after struggling 2 hours)
又一个 Googlemare Landmine ......不知何故,如果你搞砸了,你的 .gen 文件上的图标行就会消失。(我挣扎了 2 小时后的经验证明)
Insert a new icon 72x72 icon on the hdpi folder with a different name from the original, and update the name on the manifest also.
在 hdpi 文件夹中插入一个新图标 72x72 图标,其名称与原始图标不同,并更新清单上的名称。
The icon somehow resurrects on the Gen file and voila!! time to move on.
图标不知何故在 Gen 文件上复活了,瞧!!分手后要往前看了。
回答by onexf
This happens when you have previously changed your icon or the ic_launcher; and when that ic_launcher no longer exists in your base folder.
当您之前更改了图标或 ic_launcher 时会发生这种情况;当您的基本文件夹中不再存在该 ic_launcher 时。
Try adding a png image and giving the same name and then copy it to your drawable folder.Now re build the project.
尝试添加一个 png 图像并赋予相同的名称,然后将其复制到您的可绘制文件夹。现在重新构建项目。
回答by iman kazemayni
i had this problem. i created a picture for my background with jpg format. before added this picture, i changed the format to png with rename the format. and then i got this error like you. i changed my format picture with picture editor like photoshop to png and replaced it with picture in my project and then i hadnt that error. sory for bad english
我有这个问题。我用 jpg 格式为我的背景创建了一张图片。在添加这张图片之前,我将格式更改为 png 并重命名格式。然后我和你一样遇到了这个错误。我用photoshop之类的图片编辑器将我的格式图片更改为png,并在我的项目中用图片替换它,然后我没有那个错误。对不起英语不好