Android:获取abc_ic_ab_back_material的Resources $ NotFoundException [英] Android: getting Resources$NotFoundException for abc_ic_ab_back_material

本文介绍了Android:获取abc_ic_ab_back_material的Resources $ NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在较旧的(L之前的)设备上遇到了Resources $ notfoundexception.我在下面包括完整的stacktrace.

I'm getting a Resources$notfoundexception on older (pre-L) devices. I'm including the full stacktrace below.

我的支持库版本是最新版本(24.1.0),并且在gradle文件中包含以下行:

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

我的基本主题是noactionbar主题-"Theme.AppCompat.Light.NoActionBar"

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);

这可能是什么原因?此代码对所有L或以上的用户都适用.

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-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);
    }

这篇关于Android:获取abc_ic_ab_back_material的Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆