Android 资源 $NotFoundException:资源 ID #0x7f030027
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21269502/
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
Android Resources$NotFoundException: Resource ID #0x7f030027
提问by CheeseCoder
I was working on my android program and when I tried testing it I suddenly started getting an error that went "android.content.res.Resources$NotFoundException: Resource ID #0x7f030027" The last major change I made was adding in the action bar via the support library but I got that working fine already. Besides that I've added one new class but even if I delete the class and it's associated files the error still pops up. I have tried cleaning the project and restarting Eclipse multiple times to no avail.
我正在开发我的 android 程序,当我尝试测试它时,我突然开始收到一个错误“android.content.res.Resources$NotFoundException: Resource ID #0x7f030027”我所做的最后一个主要更改是通过在操作栏中添加支持库,但我已经可以正常工作了。除此之外,我添加了一个新类,但即使我删除了该类及其关联文件,错误仍然会弹出。我已经尝试清理项目并多次重新启动 Eclipse 无济于事。
Here's the stack trace in case anything got lost in translation:
这是堆栈跟踪,以防在翻译中丢失任何内容:
01-21 19:05:53.125: E/AndroidRuntime(18599): FATAL EXCEPTION: main
01-21 19:05:53.125: E/AndroidRuntime(18599): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blackhat.htmlparsingtest/com.blackhat.htmlparsingtest.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030027
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread.access0(ActivityThread.java:143)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.os.Looper.loop(Looper.java:137)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread.main(ActivityThread.java:4950)
01-21 19:05:53.125: E/AndroidRuntime(18599): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 19:05:53.125: E/AndroidRuntime(18599): at java.lang.reflect.Method.invoke(Method.java:511)
01-21 19:05:53.125: E/AndroidRuntime(18599): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
01-21 19:05:53.125: E/AndroidRuntime(18599): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
01-21 19:05:53.125: E/AndroidRuntime(18599): at dalvik.system.NativeStart.main(Native Method)
01-21 19:05:53.125: E/AndroidRuntime(18599): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030027
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.content.res.Resources.getValue(Resources.java:1026)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2131)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.content.res.Resources.getLayout(Resources.java:865)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-21 19:05:53.125: E/AndroidRuntime(18599): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.Activity.setContentView(Activity.java:1914)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
01-21 19:05:53.125: E/AndroidRuntime(18599): at com.blackhat.htmlparsingtest.MainActivity.onCreate(MainActivity.java:39)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.Activity.performCreate(Activity.java:5179)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-21 19:05:53.125: E/AndroidRuntime(18599): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
01-21 19:05:53.125: E/AndroidRuntime(18599): ... 11 more
Also I have checked the R.java file and the resource definitely exists, though as I mentioned cleaning the project, deleting the R file and restarting Eclipse does nothing. One thing I felt should be mentioned however is that I've found two R.java files, one is in my project folder along with BuildConfig.Java. The other one is in android.support.v7.appcompat. I know appcompat can cause some problems so I thought it was worth mentioning in just in case.
我还检查了 R.java 文件并且资源确实存在,尽管正如我提到的清理项目,删除 R 文件并重新启动 Eclipse 没有任何作用。但是我觉得应该提到的一件事是我找到了两个 R.java 文件,一个在我的项目文件夹中与 BuildConfig.Java 一起。另一个在 android.support.v7.appcompat 中。我知道 appcompat 会导致一些问题,所以我认为它值得一提以防万一。
I can't even get my code working how it used to, so any help would be appreciated and let me know if you need any other information!
我什至无法让我的代码像以前那样工作,所以任何帮助将不胜感激,如果您需要任何其他信息,请告诉我!
回答by Manmohan Badaya
You can check your R file for Resources$NotFoundException: Resource ID #0x7f030027
. It'll tell you which resource was creating the problem. As an alternative solution I think you might have setText
or any content just an int
.And as you know here compiler will look for corresponding resource value. So, just concat an empty string there as ""
您可以检查 R 文件中的Resources$NotFoundException: Resource ID #0x7f030027
. 它会告诉您是哪个资源造成了问题。作为替代解决方案,我认为您可能拥有setText
或任何内容只是一个int
。正如您所知,编译器将查找相应的资源值。所以,只需在那里连接一个空字符串""
回答by fWd82
I was getting this exception:
我收到此异常:
android.content.res.Resources$NotFoundException: Resource ID #0x7f02004f
android.content.res.Resources$NotFoundException: 资源 ID #0x7f02004f
I was calling PNG Icon
from
...\app\src\main\res\drawable-21
我PNG Icon
从
...\app\src\main\res\drawable-21调用
When I put my PNG Icon
into
...\app\src\main\res\drawableand I call it,
My problem goes away
当我把我PNG Icon
变成
... \程序\ SRC \主\水库\绘制和我称呼它,
我的问题解决了
BTW XML
worked from \drawable-21
顺便说一句,XML
从\drawable-21
回答by Cletus Ajibade
I had this same issue too:
我也有同样的问题:
As I was trying to move some files into another directory within the IDE, somehow I made a mistake by moving a layout xml file from the layoutdirectory into the layout-landdirectory.
当我试图将一些文件移动到 IDE 中的另一个目录时,不知何故我犯了一个错误,将布局 xml 文件从布局目录移动到layout-land目录。
It worked after I moved it back.
我把它移回去后它起作用了。
Hope this helps someone.
希望这可以帮助某人。
回答by Rahul Tiwari
For me, while creating layout file it landed in layout-land
folder, hence the exception.
Hope it will help someone.
对我来说,在创建布局文件时,它落在了layout-land
文件夹中,因此是个例外。希望它会帮助某人。
回答by murt
In my case error occured after update to Android Studio build: 3.0 Canary 6, i fixed it in downgradeing it to the previous version 3.0 Canary-5 and build tools canary-5.
在我的情况下,更新到 Android Studio build: 3.0 Canary-6 后发生错误,我在将其降级到以前的版本 3.0 Canary-5 和构建工具 canary-5 时修复了它。
The issue was related with some incompability with vector drawables on api 19 and below
该问题与 api 19 及以下版本的矢量可绘制对象的某些不兼容有关
EDIT: It's looks like that mentioned issue was resolved on Android Studio build: 3.0 Canary 7
编辑:看起来提到的问题已在Android Studio 版本中解决:3.0 Canary 7
回答by kaushik
I tried to move image files (png,jpg)from drawable-v24to drawable
我试图将图像文件(png、jpg)从drawable-v24 移动到drawable
It solved the Problem
它解决了问题
回答by Varun Kumar
I was getting this error on on Android 4.2.2 but not on Android 5 and Android 6. Reason was I had put some vector icons (xml files for navigation drawer) in drawable-v21 folder because by default android generated navigation drawer icons e.g. ic_menu_gallery.xml were residing in drawable-v21 folder. Moving these xml files (which i generated and not default ones) to drawable folder solved my problem. Don't move default generated icons to drawable else it might cause duplicate exception.
我在 Android 4.2.2 上遇到了这个错误,但在 Android 5 和 Android 6 上没有。原因是我在 drawable-v21 文件夹中放置了一些矢量图标(导航抽屉的 xml 文件),因为默认情况下 android 生成了导航抽屉图标,例如 ic_menu_gallery .xml 驻留在 drawable-v21 文件夹中。将这些 xml 文件(我生成的而不是默认的)移动到 drawable 文件夹解决了我的问题。不要将默认生成的图标移动到 drawable 否则它可能会导致重复异常。
回答by romaneso
I have just come across the same issue- cleaning and rebuilding the project solved the problem for me!
我刚刚遇到了同样的问题 - 清理和重建项目为我解决了这个问题!
回答by MattMatt
a) there could be an error in any of your resource xml files (strings, layouts, anim,etc..) and your.package.name.R cannot compile with that error
a) 您的任何资源 xml 文件(字符串、布局、动画等)中都可能存在错误,并且 your.package.name.R 无法使用该错误进行编译
EX:
前任:
<string name="main_header">My problem wasn't in java it was in this string</string>
Error:apostrophe'
needs to be preceeded by a backslash \
错误:撇号'
前面需要加反斜杠\
Correction:
更正:
<string name="main_header">My problem wasn\'t in java it was in this string</string>
or,
或者,
b) You imported the wrong "R" into your class. make sure you import your.package.name.R
and not android.R
b) 您将错误的“R”导入到您的班级中。确保你导入your.package.name.R
而不是android.R
EX:
前任:
//You DO NOT want this, unless you are working directly with android's
resources, not your own in your project
import android.R
Correction:
更正:
// You want to reference your project's resources, not Android OS's
import your_package_name_here.R
Hope this helps, Happy Coding!
希望这会有所帮助,快乐编码!
回答by Zon
You could be calling a string from project resources with
你可以从项目资源中调用一个字符串
Resources().getSystem().getString(
R.string.my_string_id)
Resources().getSystem().getString(
R.string.my_string_id)
which refers to global resources. To refer to your project resources do getString() directly from your activity:
这是指全局资源。要直接从您的活动中引用您的项目资源,请执行 getString() :
this.getString(
R.string.my_string_id); // From within your activity class.
myActivity.getString(
R.string.my_string_id); // From other classes as instance reference.