Material-components-android: [Slider] UnsupportedOperationException

Created on 18 Jun 2020  路  13Comments  路  Source: material-components/material-components-android

Description: Just add a simple slider in layout xml like this:
<com.google.android.material.slider.Slider android:layout_width="match_parent" android:layout_height="wrap_content"/>

Android API version: 27

Material Library version:1.3.0-alpha01

Device: Redmi note 4x

bug

Most helpful comment

@NVThai151097, @cdut007
I had the same problem and what I did miss was 4. Change your app theme to inherit from a Material Components theme

I had a AppTheme that was not part of Theme.MaterialComponents.xyz

Changing that fixed it for me. Hope that helps you too!

All 13 comments

Post the full stacktrace please

2020-06-19 09:06:52.749 9360-9360/com.bplus.vtpay.debug E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bplus.vtpay.debug, PID: 9360 android.view.InflateException: Binary XML file line #102: Binary XML file line #102: Error inflating class com.google.android.material.slider.Slider Caused by: android.view.InflateException: Binary XML file line #102: Error inflating class com.google.android.material.slider.Slider Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at com.Fragment.onCreateView() at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881) at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303) at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439) at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079) at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869) at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824) at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727) at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f0400ee a=3} at android.content.res.TypedArray.getColorStateList(TypedArray.java:538) at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:71) at com.google.android.material.resources.TextAppearance.<init>(TextAppearance.java:79) at com.google.android.material.resources.MaterialResources.getTextAppearance(MaterialResources.java:135) at com.google.android.material.tooltip.TooltipDrawable.loadFromAttributes(TooltipDrawable.java:151) at com.google.android.material.tooltip.TooltipDrawable.createFromAttributes(TooltipDrawable.java:111) at com.google.android.material.slider.BaseSlider.parseLabelDrawable(BaseSlider.java:466) at com.google.android.material.slider.BaseSlider.access$100(BaseSlider.java:169) at com.google.android.material.slider.BaseSlider$1.createTooltipDrawable(BaseSlider.java:360) 2020-06-19 09:06:52.750 9360-9360/com.bplus.vtpay.debug E/AndroidRuntime: at com.google.android.material.slider.BaseSlider.createLabelPool(BaseSlider.java:664) at com.google.android.material.slider.BaseSlider.setValuesInternal(BaseSlider.java:651) at com.google.android.material.slider.BaseSlider.setValues(BaseSlider.java:607) at com.google.android.material.slider.BaseSlider.processAttributes(BaseSlider.java:398) at com.google.android.material.slider.BaseSlider.<init>(BaseSlider.java:366) at com.google.android.material.slider.Slider.<init>(Slider.java:60) at com.google.android.material.slider.Slider.<init>(Slider.java:56)

For a short reason:
Caused by: android.view.InflateException: Binary XML file line #102: Error inflating class com.google.android.material.slider.Slider
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f0400ee a=3} at android.content.res.TypedArray.getColorStateList(TypedArray.java:538) at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:71) at com.google.android.material.resources.TextAppearance.<init>(TextAppearance.java:79) at com.google.android.material.resources.MaterialResources.getTextAppearance(MaterialResources.java:135) at com.google.android.material.tooltip.TooltipDrawable.loadFromAttributes(TooltipDrawable.java:151) at com.google.android.material.tooltip.TooltipDrawable.createFromAttributes(TooltipDrawable.java:111) at com.google.android.material.slider.BaseSlider.parseLabelDrawable(BaseSlider.java:466) at com.google.android.material.slider.BaseSlider.access$100(BaseSlider.java:169)

at com.google.android.material.slider.BaseSlider.createLabelPool(BaseSlider.java:664)

Please look at this. I don't know what happen with my project. If there are something need to be config please help me.

Can you post your XML?
The error is at line 103 and the cause is this one:

Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f0400ee a=3} at android.content.res.TypedArray.getColorStateList

so probably there is a XML property which is not recognized

I just add Slider to xml without any attribute like this
<com.google.android.material.slider.Slider android:layout_width="match_parent" android:layout_height="wrap_content"/>

It seems that crash happens here and the argument at index 3 is this:
a.getResourceId(R.styleable.Slider_labelStyle, R.style.Widget_MaterialComponents_Tooltip)

I've tried putting a default Slider like this without additional parameters

    <com.google.android.material.slider.Slider
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

in an XML, and it's working fine.

Does your Activity inherit from a Theme.MaterialComponents.X theme?
Have you overridden TextAppearance or something in your theme like those styles which are there?

Let me check it. I think there're something wrong in my source code too, because i have not see any same issue like this. Thank for your suggestion.

Closing since there are no updates, please re-open if you still believe the issue is on our side

i have the same issue , how to fix it?

@NVThai151097, @cdut007
I had the same problem and what I did miss was 4. Change your app theme to inherit from a Material Components theme

I had a AppTheme that was not part of Theme.MaterialComponents.xyz

Changing that fixed it for me. Hope that helps you too!

@xianmueller thx man! that worked perfectly!

Was this page helpful?
0 / 5 - 0 ratings