NinePatchDrawable上的ResourcesNotFoundException

问题描述

当我试图在下面的行中获取九个可绘制的补丁时,我遇到ResourcesNotFoundException。我遇到此问题的设备是LGE Nexus(Android 8)和Google Pixel(Android 10)。

mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
                (NinePatchDrawable) ContextCompat.getDrawable(this,R.drawable.material_shadow_z3));

例外

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo: android.content.res.Resources$NotFoundException: Resource ID #0x7f0800af
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by android.content.res.Resources$NotFoundException: Resource ID
#0x7f0800af
       at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:204)
       at android.content.res.Resources.getDrawableForDensity(Resources.java:875)
       at android.content.res.Resources.getDrawable(Resources.java:818)
       at android.content.Context.getDrawable(Context.java:605)
       at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
       at init(ImagesActivity.java:211)
       at onCreate(ImagesActivity.java:121)
       at android.app.Activity.performCreate(Activity.java:6975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

我已经在drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi,drawable-xxhdpi中提供了material_shadow_z3。就像-

material_shadow_z3.xml

<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:src="@drawable/material_shadow_z3_mdpi"
    tools:ignore="unused" />

根据评论进行更新-

material_shadow_z3_mdpi位于drawable-nodpi文件夹中,是一个9补丁的png图像。类似地,我material_shadow_z3_xhdpi,material_shadow_z3xxhdpi,material_shadow_z3_xxxhdpi位于同一个drawable-nodpi文件夹中。

与此类似- https://github.com/h6ah4i/android-advancedrecyclerview/tree/develop/example/src/main/res/drawable-nodpi

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)