Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find RippleDrawable

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 ?

like image 773
Robby Smet Avatar asked Jul 17 '15 11:07

Robby Smet


2 Answers

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.

like image 55
timemanx Avatar answered Oct 30 '22 13:10

timemanx


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.

like image 36
WindsurferOak Avatar answered Oct 30 '22 11:10

WindsurferOak