本文介绍了找不到类"android.graphics.drawable.RippleDrawable"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方库,有一种使用DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);的方法.当我在android 5.0+中测试我的应用程序时,没有问题并且运行良好.但是,在android 4.4.4中,它抛出了一个异常:

I'm using a third party library, there is a method using DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);. When I test my app in android 5.0+,there was no problem and worked well.But when it came to android 4.4.4, it threw an Exception:

    05-09 13:15:15.030 26447-26447/com.wizchen.athit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wizchen.athit, PID: 26447
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wizchen.athit/com.wizchen.athit.view.activity.MainActivity}: java.lang.NullPointerException
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2320)
   at android.app.ActivityThread.access$800(ActivityThread.java:138)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5117)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
   at android.support.v4.graphics.drawable.DrawableWrapperDonut.setCompatTintMode(DrawableWrapperDonut.java:278)
   at android.support.v4.graphics.drawable.DrawableCompatBase.setTintMode(DrawableCompatBase.java:48)
   at android.support.v4.graphics.drawable.DrawableCompat$BaseDrawableImpl.setTintMode(DrawableCompat.java:99)
   at android.support.v4.graphics.drawable.DrawableCompat.setTintMode(DrawableCompat.java:400)
   at com.wizchen.athit.lib.AppThemeEngine.util.TintHelper.createTintedDrawable(TintHelper.java:359)
   at com.wizchen.athit.lib.AppThemeEngine.viewprocessors.ToolbarProcessor.process(ToolbarProcessor.java:117)
   at com.wizchen.athit.lib.AppThemeEngine.viewprocessors.ToolbarProcessor.process(ToolbarProcessor.java:44)
   at com.wizchen.athit.lib.AppThemeEngine.ATE.postApply(ATE.java:209)
   at com.wizchen.athit.lib.AppThemeEngine.ATEActivity.onStart(ATEActivity.java:60)
   at com.wizchen.athit.view.activity.MainActivity.onStart(MainActivity.java:68)
   at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1183)
   at android.app.Activity.performStart(Activity.java:5359)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2244)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2320)
   at android.app.ActivityThread.access$800(ActivityThread.java:138)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5117)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
   at dalvik.system.NativeStart.main(Native Method)

除了上面的堆栈跟踪,我还看到一些错误信息打印在控制台中,如下所示:

Except the stack trace above, I saw some error info printed in my console like this:

05-09 13:15:15.030 26447-26447/com.wizchen.athit E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.wizchen.athit.lib.AppThemeEngine.util.TintHelper.setTintAuto

还有一个:

05-09 13:15:15.030 26447-26447/com.wizchen.athit E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.wizchen.athit.lib.AppThemeEngine.util.TintHelper.setTintSelector

我当然已经在项目中编译了v4支持库:)

Of course I have compiled the v4 support library in my project :)

谁遇到了这个问题?感谢您的帮助!

Who have encountered this problem? Thanks for help!

-------------------------------------------- ----------------------------------------------
更新1:这是导致NullPointerException的原因:

------------------------------------------------------------------------------------------
Update 1:this is what causes NullPointerException:

    @CheckResult
    @Nullable
    public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int color) {
        if (drawable == null) return null;
        drawable = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
        DrawableCompat.setTint(drawable, color);
        return drawable;
    }

推荐答案

阅读:

如果您查看DrawableCompat的源代码,则将看到任何版本的< support library 21 该方法不执行任何操作.

DrawableCompat的想法似乎并不是在旧版本上崩溃,而是实际提供了该功能.

The idea of DrawableCompat seems to be simply not crashing on old versions, rather than actually providing that functionality.

使用support library 22.1,您可以使用DrawableCompat着色可绘制对象.

With support library 22.1 you can use DrawableCompat to tint drawables.

这篇关于找不到类"android.graphics.drawable.RippleDrawable"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:22