Could not find RippleDrawable
Asked Answered
M

2

10

I want to create a ripple dynamically in code.

Code:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      buyButton.setBackground(getPressedColorRippleDrawable(primaryColor, darkerVariant));
}

public static RippleDrawable getPressedColorRippleDrawable(int color, int darkerVariant) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ColorStateList colorStateList = new ColorStateList(
                new int[][]
                        {new int[]{}},
                new int[]
                        {darkerVariant}
        );
        return new RippleDrawable(colorStateList, new ColorDrawable(color), null);
    }
    return null;
}

This works on Lollipop but makes the app crash on my GNEX (4.3).
Error:

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method fragments.ProductDetailFragment.getPressedColorRippleDrawable

07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime﹕ FATAL EXCEPTION: main

java.lang.VerifyError: fragments/ProductDetailFragment

But RippleDrawable is never used on Gnex because code isn't executed.

How can I fix this ?

Mercurochrome answered 17/7, 2015 at 11:0 Comment(0)
L
8

The issue is that you need to return a Drawable instead of a RippleDrawable in getPressedColorRippleDrawable. Otherwise, on pre-lollipop devices, you will get a VerifyError.

Leshia answered 10/3, 2016 at 5:11 Comment(0)
C
4

That code is indeed not being executed. The app crashes because you're receiving a java.lang.VerifyError. Try performing a Project → Clean if you're using Eclipse or Build → Rebuild project if you're using Android Studio.

Curvature answered 17/7, 2015 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.