I have a TabActivity that seems to be dieing on a small set of phones when I add the Drawable to it. From the reports, the same tab code ran successfully at one point, but suddenly stopped during one launch(usually via pending intent)
The code thats executing in onCreate is this
spec = theTtabHost.newTabSpec(STATS_TAG).setIndicator(getText(R.string.statsTab),
res.getDrawable(R.drawable.ic_tab_stats))
The stack trace I receive is here
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.Main}: android.content.res.Resources$NotFoundException: File res/drawable/ic_tab_stats.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_tab_stats.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.Resources.getDrawable(Resources.java:590)
at com.test.Main.onCreate(Main.java:162)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
... 11 more
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 15 more
The ic_tab_stats.xml file is in drawable, and is here.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/stats"
android:state_selected="true" />
<item android:drawable="#drawable/stats_deselect" />
</selector>
The stats.png and stats_deselect.png are peers inside drawable. hdpi and ldpi do not have either file, and mdpi is empty. My app supports back to 1.5, so I used drawable instead of mdpi.
From the reports, it seems to be pretty random.
Turns out this is sort of normal behavior on Android upgrades.
Related
I'm getting a Resources$notfoundexception on older (pre-L) devices. I'm including the full stacktrace below.
My version of the support library is the latest (24.1.0), and I've included in my gradle file the line:
vectorDrawables.useSupportLibrary = true
My base theme is a noactionbar theme - "Theme.AppCompat.Light.NoActionBar"
The crash is happening on this line in my code where I reference the back arrow in a support-toolbar in order to later change it's color:
#SuppressLint("PrivateResource") final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
What could be the cause of this? This code works fine for all users with L or above.
07-19 22:36:57.029 9330-9330/mypkg E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {mypkg/mypkg.activites.myActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:1957)
at android.content.res.Resources.getDrawable(Resources.java:673)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
at mypkg.base.mymethod(myactivity.java:100)
at mypkg.mymethod(myactivity.java:100)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:511)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:178)
at android.app.Activity.performResume(Activity.java:5341)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
at android.content.res.Resources.loadDrawable(Resources.java:1954)
at android.content.res.Resources.getDrawable(Resources.java:673)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
at mypkg/mymethod(myactivity.java:100)
at mypkg/mymethod(myactivity.java:100)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:511)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:178)
at android.app.Activity.performResume(Activity.java:5341)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
The answer to this turned out to be buried at the bottom of this guide:
https://medium.com/#chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.xucjbsts0
It turns out that all you need to add this line in at the beginning of the activity that will use the resource:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Please make sure you are using AppCompatActivity instead Activity. If you're using AppCompat's theme, then you also need to use it's Activity.
Another solution,
in addition to AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
is to wrap your vector drawable into another drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_your_vector"/>
</selector>
Might be useful when you use as a drawable for a TextView (i.e. DrawableLeft)
Accepted answer is not covered all cases. It will not work on Android 4.0.3/4.1.1/4.1.2 platform with 25.x.x support library. The right way to fix problem with abc_ic_ab_back_material.xml is to override homeAsUpIndicator attribute in your theme. For example, my theme is inherited from Theme.AppCompat.Light.NoActionBar. As for value of mentioned attribute, you can use #drawable/abc_ic_ab_back_mtrl_am_alpha or your custom 'back' drawable.
private resources its treated differently at compile time and runtime..to fix I usually take the offending private resource and backport it to my app in my res files
I was using the application context when calling ContextCompat.getDrawable() which also crashes the app with Resources$NotFoundException and now the following message even though everything else was set up just fine:
If the resource you are trying to use is a vector resource, you may be
referencing it in an unsupported way. See
AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
All I had to do was to change to the view's Context. :)
Instead of:
ContextCompat.getdrawable()
Try using:
AppCompatDrawableManager.get().getDrawable()
Apologies if this is a duplicate, I did try and find any similar answers first and failed as nothing seemed to refer to ImageView? I'm not an Android dev, but we are seeing issues with our app on older OS versions!
Stack trace:
02-20 09:56:15.885 11529-11529/com.octer E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010076 a=2}
at android.content.res.Resources.loadDrawable(Resources.java:2063)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:3364)
at android.widget.ImageView.<init>(ImageView.java:121)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton.<init>(ActionMenuPresenter.java:556)
at com.android.internal.view.menu.ActionMenuPresenter.initForMenu(ActionMenuPresenter.java:99)
at com.android.internal.view.menu.MenuBuilder.addMenuPresenter(MenuBuilder.java:216)
at com.android.internal.widget.ActionBarView.configPresenters(ActionBarView.java:483)
at com.android.internal.widget.ActionBarView.setMenu(ActionBarView.java:448)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:405)
at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:775)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:198)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
I did discover this post on the internet but none of the solutions seems to have fixed anything. The problem is the code builds and runs on Nexus 5, but not on older model phones.
Debug resource not found website
For all those interested, our issue was resolved when removing the following parent attribute, from one of our tags:
parent="#style/Widget.AppCompat.ActionButton.Overflow"
It's a pretty horrendous stack-trace, which didn't resolve to any logical location - we managed to isolate it after many hours of (Delete, build, delete, build...etc)
<style name="OcterActionBarOverflowButton">
Hope this helps!
I fixed this error by moving my drawable from
app\src\main\res\drawable-v24
to
app\src\main\res\drawable
We've seen about 40 of these crashes in the past two days of our app release for 4.0. After reviewing crash logs, we've discovered it's existence since version 3.3 of our app. We have been unable to reproduce this in house.
Further research has indicated this problem is prevalent in other applications, but I was unable to find a resolution or an indication that Google is aware of the issue.
The crash itself happens on the setContentView(R.layout.foo) method call in onCreate()
Notes:
We limit our API to version 4 and target 15.
We've seen this on at least 2.2 - 4.0.3 on mdpi,hdpi,xhdpi phones and tablets.
User comments specify that the app crashes immediately (expected) and that the Evernote icon in the application launcher turns to the default app icon (cannot read any drawables).
The crash is not limited to one specific drawable, we have seen many different ones in the logs, however they all "seem" to be image drawables, not colors, layouts, xml files, etc...
This is not limited to 9patches, it has happened on both regular .png and .9.png
Our drawable folders look like the picture attached
We store only xml in our drawable folder
Stack trace:
android.content.res.Resources$NotFoundException: File res/drawable/ics_tab_title_unselected.xml from drawable resource ID #0x7f02016f
at android.content.res.Resources.loadDrawable(Resources.java:1697)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.view.View.setBackgroundResource(View.java:7533)
at com.evernote.ics.ActionBarTabbedTitle.a(ActionBarTabbedTitle.java:103)
at com.evernote.ics.j.a(ActivityActionBar.java:150)
at com.evernote.ics.a.c(ActionBar.java:731)
at com.evernote.ics.a.p(ActionBar.java:440)
at com.evernote.ics.a.g(ActionBar.java:423)
at com.evernote.ics.j.m(ActivityActionBar.java:68)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.s(SwipeableTabbedActivityAbstract.java:990)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.a(SwipeableTabbedActivityAbstract.java:662)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.b(SwipeableTabbedActivityAbstract.java:617)
at com.evernote.ics.phone.PhoneMainActivity.b(PhoneMainActivity.java:113)
at com.evernote.ui.EvernoteFragment.a(EvernoteFragment.java:136)
at com.evernote.ui.EvernoteFragment.a(EvernoteFragment.java:132)
at com.evernote.ui.EvernoteFragment.d(EvernoteFragment.java:128)
at com.evernote.ics.phone.b.onItemClick(HomeFragment.java:1324)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3513)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/tab_unselected_focus.9.png from drawable resource ID #0x7f0201e6
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1694)
... 28 more
Caused by: java.io.FileNotFoundException: res/drawable-xhdpi-v4/tab_unselected_focus.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:406)
at android.content.res.Resources.loadDrawable(Resources.java:1706)
... 33 more
Any recommendations would greatly be appreciated.
App: https://play.google.com/store/apps/details?id=com.evernote
Thanks,
Ty
similar error solved by adding the following in the "proguard" file.
-keepclassmembers class **.R$* {
public static <fields>;
}
I've got couple reports on Market about this exception. There is no reference to where it happens in my app and majority of users do not have thit issue. How do I debug something like that? This is NOT exception I get from all devices. Just one specific device might report it.
android.content.res.Resources$NotFoundException: Resource ID #0x109005d
at android.content.res.Resources.getValue(Resources.java:892)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
at android.content.res.Resources.getLayout(Resources.java:731)
at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2451)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2506)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1626)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Maybe there is some resource that is defined in a specific folder and is not in a less specific folder? Like, you defined a drawable X in the folder drawable-land and not in the drawable-port? You should double-check your specific folders for resources that are not in other folders
By chance do you use this resource: com.android.internal.R.layout.search_dropdown_item_icons_2line ? Since it is an internal package, maybe not all implementations contain it (or not each API level), or contain it but with different resource identifier.
The app works fine on HPDI and MDPI, but when run in an LDPI (v2.0) emulator, I get the exception and stack trace below.
Why is it looking for this image? (it's not referenced in my application, I've checked). The starter activity has disabled the title bar in any case.
If the OS expects this image, why is it not present?
Why is the exception relating to an MPDI image, when the emulator is LDPI?
04-20 11:35:19.432: ERROR/AndroidRuntime(236): Uncaught handler: thread main exiting due to uncaught exception
04-20 11:35:19.502: ERROR/AndroidRuntime(236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spondle/com.spondle.EventsActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4310)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
at android.app.Activity.setContentView(Activity.java:1622)
at com.spondle.EventsActivity.onCreate(EventsActivity.java:38)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.ImageView.<init>(ImageView.java:105)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 23 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-mdpi/title_bar_shadow.9.png from drawable resource ID #0x7f02002a
at android.content.res.Resources.loadDrawable(Resources.java:1710)
at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
at android.widget.ImageView.<init>(ImageView.java:115)
... 27 more
Caused by: java.io.FileNotFoundException: res/drawable-mdpi/title_bar_shadow.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:391)
at android.content.res.Resources.loadDrawable(Resources.java:1702)
... 29 more
If the OS expects this image, why is it not present?
Why is the exception relating to an MPDI image, when the emulator is LDPI?
If the requested resource (title_bar_shadow.9.png) is not present in drawable-ldpi (and it wasn't until Android 2.3), Android will try to find the best match (drawable-mdpi will be the next folder to search in). Anyway, the file will not be found there either (again, it was not there until Android 2.3). So the next step would be to search for it in drawable-hdpi (where it can be found). But apparently the search stops on drawable-mdpi (which is strange... maybe a bug in Android 2.1? you could try Android 2.2 emulator)
Why is it looking for this image? (it's not referenced in my application, I've checked). The starter activity has disabled the title bar in any case.
This image (shadow) is not used by the title bar. It is displayed UNDER the title bar.
To make it disappear, you have to create your own theme, like this:
<style
name="Theme"
parent="android:Theme.NoTitleBar">
<item
name="android:windowContentOverlay">#null</item>
</style>
I solved this problem making a copy of the images from drawable-ldpi/mdip/hdpi to a drawable (only drawable) folder. Put in this folder your low resolution images.
You don't need to have a title_bar_shadow.9.png file on these folders.