Android资源$NotFoundException:资源ID #0x7f030027。

时间:2021-02-01 00:32:44

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”的错误。资源$NotFoundException:资源ID #0x7f030027”我所做的最后一个重大改变是通过支持库添加了action bar,但是我已经得到了工作的良好效果。除此之外,我添加了一个新类,但即使我删除了类,它的相关文件仍然会出现错误。我已经尝试过清理这个项目,并多次重启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.access$700(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!

我甚至不能让我的代码正常工作,所以任何帮助都会被欣赏,如果你需要其他信息,请告诉我!

14 个解决方案

#1


69  

You can check your R file for Resources$NotFoundException: Resource ID #0x7f030027. It'll tell you which resource was creating problem. As an alternative sollution 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文件的资源$NotFoundException:资源ID #0x7f030027。它会告诉你哪个资源造成了问题。作为另一种解决方案,我认为您可能有setText或任何内容,正如您所知道的,编译器将查找相应的资源值。因此,将一个空字符串concat作为""

#2


7  

I was getting this exception:

我得到了一个例外:

android.content.res.Resources$NotFoundException: Resource ID #0x7f02004f

android.content.res。# 0 x7f02004f NotFoundException美元资源:资源ID

I was calling PNG Icon from ...\app\src\main\res\drawable-21

我用的是…\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。

When I put my PNG Icon into ...\app\src\main\res\drawable and I call it,
My problem goes away

当我把我的PNG图标放进…\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \可drawable,我叫它,我的问题消失了。

BTW XML worked from \drawable-21

BTW XML的工作原理是\drawable-21。

#3


6  

Had this same issue too.

也有同样的问题。

But it turned out as I was moving things around in my IDE I wrongly moved a layout resource(xml) from the layout directory into layout-land.

但是,当我在IDE中移动东西时,我错误地将布局资源(xml)从布局目录移动到layout-land。

It worked after I moved it back.

我把它搬回来后,它就起作用了。

Hope this helps someone.

希望这可以帮助别人。

#4


5  

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 cani -5和构建工具can- 5。

The issue was related with some incompability with vector drawables on api 19 and below

这个问题与api 19和下面的矢量drawables有关。

EDIT: It's looks like that mentioned issue was resolved on Android Studio build: 3.0 Canary 7

编辑:看起来,上面提到的问题在Android Studio build: 3.0 Canary 7中得到了解决。

#5


5  

For me, while creating layout file it landed in layout-land folder, hence the exception. Hope it will help someone.

对我来说,在创建布局文件时,它在layout-land文件夹中着陆,因此有例外。希望它能帮助别人。

#6


2  

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文件(字符串、布局、anim等)和your. package.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”导入你的课堂。确保你导入了你的。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!

希望这能帮助你,快乐的编码!

#7


2  

I have just come across the same issue- cleaning and rebuilding the project solved the problem for me!

我刚刚遇到了同样的问题——清理和重建项目解决了我的问题!

#8


1  

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文件夹中解决了我的问题。不要将默认生成的图标移动到可拖放的图标中,否则会导致重复的异常。

#9


0  

Look at this link , maybe it will help you , it is the same problem. If the cleaning of project does not help you try to delete your r.java file it will be generated itself. Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android

看看这个链接,也许它会帮助你,这是同样的问题。如果项目的清理没有帮助您试图删除您的r。java文件将自动生成。android.content.res。资源$NotFoundException:即使资源存在于android中,也要例外。

#10


0  

Your probably developing for newer android version from your current device. Try download SDK that is appropriate to your testing device.

你可能正在开发新的android版本,从你现在的设备。尝试下载适合您的测试设备的SDK。

#11


0  

If you're using vector drawable in the resource.xml which has a <layer-list> on API version 19 or lower you will get this exception

如果你在资源中使用向量。在API版本19或更低的版本中有 的xml将会得到这个异常。

#12


0  

In my case I was using a custom style for my vertical scrollbar in scroll view like this:

在我的例子中,我在滚动视图中使用了一个自定义样式,如下所示:

 <ScrollView
        android:id="@+id/scroller"
        style="@style/scrollbar_shape_style"
  ..>

and my style was like:

我的风格是:

 <style name="scrollbar_shape_style">
  ...

I changed the first part to this:

我把第一部分改成了这个:

<ScrollView
    android:id="@+id/scroller"
    android:theme="@style/scrollbar_shape_style"

and added parent to the style like this:

并增加了这样的父母:

<style name="scrollbar_shape_style" parent="LightTheme">

and problem solved.

和问题解决。

#13


0  

You could be calling a string from project resources with

您可以从项目资源中调用一个字符串。

Resources().getSystem().getString( R.string.my_string_id)

资源().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.

#14


0  

You might used same resource photo twice.
this happened with me when used photo twice:
first time in main screen then used the same photo in another activity.

您可能会使用相同的资源照片两次。这发生在我使用照片两次:第一次在主屏幕上使用相同的照片在另一个活动。

#1


69  

You can check your R file for Resources$NotFoundException: Resource ID #0x7f030027. It'll tell you which resource was creating problem. As an alternative sollution 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文件的资源$NotFoundException:资源ID #0x7f030027。它会告诉你哪个资源造成了问题。作为另一种解决方案,我认为您可能有setText或任何内容,正如您所知道的,编译器将查找相应的资源值。因此,将一个空字符串concat作为""

#2


7  

I was getting this exception:

我得到了一个例外:

android.content.res.Resources$NotFoundException: Resource ID #0x7f02004f

android.content.res。# 0 x7f02004f NotFoundException美元资源:资源ID

I was calling PNG Icon from ...\app\src\main\res\drawable-21

我用的是…\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。

When I put my PNG Icon into ...\app\src\main\res\drawable and I call it,
My problem goes away

当我把我的PNG图标放进…\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \可drawable,我叫它,我的问题消失了。

BTW XML worked from \drawable-21

BTW XML的工作原理是\drawable-21。

#3


6  

Had this same issue too.

也有同样的问题。

But it turned out as I was moving things around in my IDE I wrongly moved a layout resource(xml) from the layout directory into layout-land.

但是,当我在IDE中移动东西时,我错误地将布局资源(xml)从布局目录移动到layout-land。

It worked after I moved it back.

我把它搬回来后,它就起作用了。

Hope this helps someone.

希望这可以帮助别人。

#4


5  

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 cani -5和构建工具can- 5。

The issue was related with some incompability with vector drawables on api 19 and below

这个问题与api 19和下面的矢量drawables有关。

EDIT: It's looks like that mentioned issue was resolved on Android Studio build: 3.0 Canary 7

编辑:看起来,上面提到的问题在Android Studio build: 3.0 Canary 7中得到了解决。

#5


5  

For me, while creating layout file it landed in layout-land folder, hence the exception. Hope it will help someone.

对我来说,在创建布局文件时,它在layout-land文件夹中着陆,因此有例外。希望它能帮助别人。

#6


2  

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文件(字符串、布局、anim等)和your. package.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”导入你的课堂。确保你导入了你的。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!

希望这能帮助你,快乐的编码!

#7


2  

I have just come across the same issue- cleaning and rebuilding the project solved the problem for me!

我刚刚遇到了同样的问题——清理和重建项目解决了我的问题!

#8


1  

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文件夹中解决了我的问题。不要将默认生成的图标移动到可拖放的图标中,否则会导致重复的异常。

#9


0  

Look at this link , maybe it will help you , it is the same problem. If the cleaning of project does not help you try to delete your r.java file it will be generated itself. Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android

看看这个链接,也许它会帮助你,这是同样的问题。如果项目的清理没有帮助您试图删除您的r。java文件将自动生成。android.content.res。资源$NotFoundException:即使资源存在于android中,也要例外。

#10


0  

Your probably developing for newer android version from your current device. Try download SDK that is appropriate to your testing device.

你可能正在开发新的android版本,从你现在的设备。尝试下载适合您的测试设备的SDK。

#11


0  

If you're using vector drawable in the resource.xml which has a <layer-list> on API version 19 or lower you will get this exception

如果你在资源中使用向量。在API版本19或更低的版本中有 的xml将会得到这个异常。

#12


0  

In my case I was using a custom style for my vertical scrollbar in scroll view like this:

在我的例子中,我在滚动视图中使用了一个自定义样式,如下所示:

 <ScrollView
        android:id="@+id/scroller"
        style="@style/scrollbar_shape_style"
  ..>

and my style was like:

我的风格是:

 <style name="scrollbar_shape_style">
  ...

I changed the first part to this:

我把第一部分改成了这个:

<ScrollView
    android:id="@+id/scroller"
    android:theme="@style/scrollbar_shape_style"

and added parent to the style like this:

并增加了这样的父母:

<style name="scrollbar_shape_style" parent="LightTheme">

and problem solved.

和问题解决。

#13


0  

You could be calling a string from project resources with

您可以从项目资源中调用一个字符串。

Resources().getSystem().getString( R.string.my_string_id)

资源().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.

#14


0  

You might used same resource photo twice.
this happened with me when used photo twice:
first time in main screen then used the same photo in another activity.

您可能会使用相同的资源照片两次。这发生在我使用照片两次:第一次在主屏幕上使用相同的照片在另一个活动。