Android Resources$NotFoundException: Resource ID #0x7f030027
AndroidAndroid ResourcesAndroid Problem Overview
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.
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.
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!
Android Solutions
Solution 1 - Android
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 ""
Solution 2 - Android
I was getting this exception: > android.content.res.Resources$NotFoundException: Resource ID #0x7f02004f
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
BTW XML
worked from \drawable-21
Solution 3 - Android
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 layout directory into the layout-land directory.
It worked after I moved it back.
Hope this helps someone.
Solution 4 - Android
I tried to move image files (png,jpg) from drawable-v24 to drawable
It solved the Problem
Solution 5 - Android
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.
The issue was related with some incompability with vector drawables on api 19 and below
EDIT: It's looks like that mentioned issue was resolved on Android Studio build: 3.0 Canary 7
Solution 6 - Android
For me, while creating layout file it landed in layout-land
folder, hence the exception.
Hope it will help someone.
Solution 7 - Android
I have just come across the same issue- cleaning and rebuilding the project solved the problem for me!
Solution 8 - Android
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
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
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!
Solution 9 - Android
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.
Solution 10 - Android
You could be calling a string from project resources with
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:
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.
Solution 11 - Android
First step :
ctrl + maj + f : look for the code of the issue here = #0x7f030027
2nd step Read the name of the value, find where it is used.
3rd step If it is a PNG maybe you have not put all different sizes of it.
Solution 12 - Android
Solution 13 - Android
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. https://stackoverflow.com/questions/9161435/getting-android-content-res-resourcesnotfoundexception-exception-even-when-the
Solution 14 - Android
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
Solution 15 - Android
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.
Solution 16 - Android
I encountered the ResourceException problem when I first use BottomNavigationDrawer widget. Tyr to add all resourses for all possible dimensions, in the end, I got rid of the problem by removing all drawable-v21, and drawable-v24 folders, just leaving the conventional drawable folders.
Solution 17 - Android
Was facing this issue using a custom UI library, so app:srcCompt was not available. I was using latest gradle build(v3.4.1) and after downgrading to v3.2.1 the problem was fixed.
Solution 18 - Android
In my case, I was setting an integer value to the TextView.setText()
. Because it was an int, it was assuming that it's a resource id which of course wasn't the case.
year = 1947;
textView.setText(year) ------>>>> Error!
Fixed it by converting the integer value to string-
textView.setText(year + "");
or
textView.setText(String.valueOf(year));
Solution 19 - Android
Your probably developing for newer android version from your current device. Try download SDK that is appropriate to your testing device.
Solution 20 - Android
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.