Cannot render MaterialButton with android.material:1.1.x-ThrowExceptions

Exception or error:

Whenever I use MaterialButton, I get the following exception in the xml preview:

java.lang.IllegalArgumentException: java.lang.ClassCastException

I have upgraded to android studio 3.4 and to

Version 1.0.0 works but any 1.1.x doesn’t.

Is this a problem with the IDE or the library?

For reference, the full stacktrace:

    at sun.reflect.GeneratedMethodAccessor893.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at android.animation.PropertyValuesHolder_Delegate.callMethod(
    at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(
    at android.animation.PropertyValuesHolder.nCallFloatMethod(
    at android.animation.PropertyValuesHolder.access$400(
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(
    at android.animation.ObjectAnimator.animateValue(
    at android.animation.ValueAnimator.animateBasedOnTime(
    at android.animation.ValueAnimator.doAnimationFrame(
    at android.animation.ValueAnimator.pulseAnimationFrame(
    at android.animation.AnimatorSet.pulseFrame(
    at android.animation.AnimatorSet.handleAnimationEvents(
    at android.animation.AnimatorSet.doAnimationFrame(
    at android.animation.AnimationHandler.doAnimationFrame(
    at android.animation.AnimationHandler.access$100(
    at android.animation.AnimationHandler$1.doFrame(
    at android.view.Choreographer$
    at android.view.Choreographer.doCallbacks(
    at android.view.Choreographer_Delegate.doFrame(
    at java.util.concurrent.CompletableFuture$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

EDIT This happens only when the button style is not set OR the defaulted:


Setting as unelevated style works for example, so as a work around I’m using the tools namespace to show unelevated button style.

Edit 2 the app theme parent is already correctly set as Theme.AppCompat.Light.DarkActionBar. This is an IDE issue as it is running well on my emulator and device. I have also done a clear cache & invalidate, clean build, rebuild… (the standard things we do when faced with weird IDE problems)

Edit 3 Still no luck with the latest A.S. 3.4.1!

How to solve:

Update3: This is finally fixed in Studio 3.5beta2! We did it guys! 🥳

Update2: I’ve filed an issue here: Please star for visibility.

Update: This is a cleaner workaround since we don’t have to litter tools:style throughout our xml layouts. This has stopped working for me for no apparent reason, I’ve had to revert to my original workaround described below.

Here’s a workaround till we get an actual fix, based on Gautham’s discovery:

Add this style to your styles.xml:

<!--  For the sake of xml preview not breaking  -->
    <style name="UnelevatedButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">

Add it to your Buttons like so:


Note that the ordering of the two is important, the tools line needs to come first.

You can update your UnelevatedButton to match your ActualButtonStyle for the sake of having previews consistent with your actual runtime buttons.


I’m attempting to reproduce this issue currently, but I need more information. My current hypothesis is that it’s related to button elevation (based on the animation calls in the stacktrace), which is also why unelevated button works as expected.

Could you please file an issue at with the component name and description, as well as the information requested there?


amitav13’s solution has one major problem, when you reformat the code the default rules will rearrange all the attributes and then everything breaks again.

Instead, until this is fixed, my proposal is to create a separate application theme for using in preview windows, in this example this Theme is called AppTheme.PreviewFix.
Simply select this theme in Preview / Design panes.


<?xml version="1.0" encoding="utf-8"?>
   <attr name="buttonStyle" format="reference" />


<?xml version="1.0" encoding="utf-8"?>
    <style name="AppTheme" parent="Theme.MaterialComponents">
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryDarkColor</item>
        <item name="colorSecondary">@color/secondaryColor</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="buttonStyle">@style/AppTheme.Button</item>

    <style name="AppTheme.PreviewFix" parent="AppTheme">
        <item name="buttonStyle">@style/AppTheme.Button.PreviewFix</item>

    <style name="AppTheme.Button" parent="Widget.MaterialComponents.Button"/>

    <style name="AppTheme.Button.PreviewFix" parent="Widget.MaterialComponents.Button.UnelevatedButton"/>




Set your application theme from AppCompat to MaterialComponents such as below:

Use below style:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

instead of

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>


I had the same problem, I’ve downloaded another version of Android Studio.

It’s Working Fine on A.S. 3.6 Canary 3…
I’m Using API 29, and material_version = ‘1.1.0-alpha08’

Download it here

The last working version for my earlier Android Studio was material_version = ‘1.0.0’.

But it didn’t have some of the new material component features, so Instead of rolling back, I decided to Update Android Studio.

Do what best suits your needs.


Leave a Reply

Your email address will not be published. Required fields are marked *