54

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!

CheeseCoder
  • 701
  • 1
  • 7
  • 11

20 Answers20

103

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 ""

aminography
  • 21,986
  • 13
  • 70
  • 74
Manmohan Badaya
  • 2,326
  • 1
  • 22
  • 35
  • That actually helped! As it turned out, somehow at some point the xml file got deleted from the layout folder... I appreciate the help! – CheeseCoder Jan 22 '14 at 04:39
  • 6
    `You might have set text or any content just an int` Yes...That's the mistake I was doing..Thank you @Manmohan – Prabs Jul 13 '15 at 12:48
  • 1
    "You might have set text or any content just an int", yes it happened to me, once I put "String.valueOf(myInteger)" then everything is OK. Thanks. – danisupr4 Feb 22 '16 at 16:08
  • This helped me find the "problematic" resource however it is defined in mdpi, hdpi, xhdpi, and xxhdpi. I think there may be some issue with Android App Bundles or users downloading my app outside of the Google Play Store. I am really not sure what is causing this issue. – Etienne Lawlor Apr 27 '19 at 07:33
  • @toobsco42, are you using .aab too? I got this kind of error in my aab logs – thecr0w Feb 27 '20 at 01:59
26

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

fWd82
  • 840
  • 1
  • 13
  • 31
12

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.

Cletus Ajibade
  • 1,550
  • 15
  • 14
  • 2
    This answer saved me! At first I didn't understand what the answer meant, so for anyone who needs instructions: View->Tool Windows ->Project And then check on which folder the layout is at. – Json Jun 02 '18 at 16:56
8

I tried to move image files (png,jpg) from drawable-v24 to drawable

It solved the Problem

kaushik
  • 556
  • 1
  • 7
  • 22
7

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

murt
  • 3,790
  • 4
  • 37
  • 48
4

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

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
3

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

romaneso
  • 1,097
  • 1
  • 10
  • 26
  • 1
    I restarted Visual studio, deleted bin and obj folder. Cleaned and rebuild the project and finally the issue got resolved. Thanks. – Arun Prasad May 08 '18 at 07:20
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

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!

MattMatt
  • 905
  • 6
  • 19
  • Now that you mention it, when creating the new class I originally had it not modify strings.xml, nor create a menu or layout (since I planned to use a different menu and layout file anyway. Could this cause situation A? – CheeseCoder Jan 21 '14 at 21:47
  • No that shouldn't affect it, and if it did, I'm sure it wouldn't do it with errors. See my updated answer. Hope it helps – MattMatt Jan 21 '14 at 22:52
  • Checked my code after your edit, and I noticed that R isn't imported at all. I don't recall ever importing it either, though I could be wrong. I don't know if that makes a difference but if so then I have no idea how the import got removed from all of my classes without me directly editing them. Thanks for your reply! – CheeseCoder Jan 22 '14 at 01:00
  • If you are not importing R (no `setContentView(R.layout.my_layout)`) then I beleive your error lies in xml somewhere. I may be wrong but that's all I can think of. run android lint, it may help you out – MattMatt Jan 22 '14 at 02:03
2

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.

Varun Kumar
  • 2,543
  • 1
  • 23
  • 22
1

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.
Zon
  • 18,610
  • 7
  • 91
  • 99
1

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. /Users/churlet/Desktop/Capture d’écran 2018-08-06 à 10.31.06.png

Nicoolasens
  • 2,871
  • 17
  • 22
1

drawable folder image

replace image icon from drawable-v24 to drawable, that solved my issue

zaheer
  • 143
  • 10
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

Community
  • 1
  • 1
HK.avdalyan
  • 724
  • 1
  • 6
  • 21
  • Nope, I tried deleting R.Java as it recommended, and I'm still getting the same error. – CheeseCoder Jan 21 '14 at 21:43
  • I am getting this error only on Galaxy S5 not with a Motorola phone. Why is this? – The_Martian Oct 20 '15 at 05:42
  • @The_Martian This is most likely because your issue is due to different phone densities. Check that any file you a referencing is in all of the stalks for both devices as maybe it can't find a file on on device. – edwoollard Dec 07 '17 at 20:38
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

Ali
  • 2,427
  • 22
  • 25
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.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
0

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.

0

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.

Karani.pranay
  • 191
  • 2
  • 11
0

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));
Manish Paul
  • 171
  • 1
  • 5
-1

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

Eli
  • 586
  • 2
  • 12
  • 28
-2

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.

Amr
  • 1,068
  • 12
  • 21