android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow

I get this error when calling setBackgroundColor() method, which is defined in View class.

cardView.setBackgroundColor(Color.parseColor("#ffffcc"));

Instead setCardBackgroundColor() method should be called, which is specific to CardViews and defined within CardView class.

This code setting both background colour and the corner radius works for me:

cardView.setCardBackgroundColor(Color.parseColor("#ffffcc"));
cardView.setRadius(50);

Leave a Comment