material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

[ShapeableImageView] Crash occasionally #3296

Open chenqingru opened 1 year ago

chenqingru commented 1 year ago

Description: Hi, I found a crash on ShapeableImageView. The version used is 1.5.0. Error log : ResourcesCompat: Failed to inflate ColorStateList, leaving it to the framework ResourcesCompat: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0400f3 a=-1} ResourcesCompat: at android.content.res.TypedArray.getColor(TypedArray.java:477) ResourcesCompat: at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:13) ResourcesCompat: at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:13) ResourcesCompat: at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:18) ResourcesCompat: at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:13) ResourcesCompat: at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:13) ResourcesCompat: at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:9) ResourcesCompat: at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:1) ResourcesCompat: at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:3) ResourcesCompat: at com.google.android.material.imageview.ShapeableImageView.(ShapeableImageView.java:18) ResourcesCompat: at com.google.android.material.imageview.ShapeableImageView.(ShapeableImageView.java:2) ResourcesCompat: at java.lang.reflect.Constructor.newInstance0(Native Method) ResourcesCompat: at java.lang.reflect.Constructor.newInstance(Constructor.java:343) ResourcesCompat: at android.view.LayoutInflater.createView(LayoutInflater.java:647) ResourcesCompat: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:807) ResourcesCompat: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) ResourcesCompat: at android.view.LayoutInflater.rInflate(LayoutInflater.java:880) ResourcesCompat: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:841) ResourcesCompat: at android.view.LayoutInflater.inflate(LayoutInflater.java:515) ResourcesCompat: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)

Expected behavior: ShapeableImageView doesn't crash

Source code: the crash on source code is: TypedArray

if (type == TypedValue.TYPE_ATTRIBUTE) { final TypedValue value = mValue; getValueAt(index, value); throw new UnsupportedOperationException( "Failed to resolve attribute at index " + attrIndex + ": " + value

Minimal sample app repro: use it in layout.xml for example: <com.google.android.material.imageview.ShapeableImageView android:id="@+id/big_setting_account_avator" android:layout_width="@dimen/big_setting_user_avatar" android:layout_height="@dimen/big_setting_user_avatar" android:layout_alignParentEnd="true" android:layout_marginTop="@dimen/big_setting_user_avatar_margin_top" android:layout_marginEnd="@dimen/big_setting_account_avator_margin_end" android:visibility="invisible" app:shapeAppearance="@style/PortraitCircle" /> Android API version: 33

Material Library version: 1.5.0

Device: Device on which the bug was encountered here

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

paulfthomas commented 1 year ago

Hi @chenqingru , could you try on the latest version of the library (1.8.0)?

chenqingru commented 1 year ago

ok,thanks for you reply

drchen commented 1 year ago

Is the issue still happening with the latest library version?

Pittvandewitt commented 1 year ago

The same exception occurs with MaterialDivider on initialization. Library version 1.9.0

AkshayAshokCode commented 7 months ago

This issue for ShapeableImageView is still there in the version: 1.12.0-beta01

zjbpku commented 2 months ago

should set strokeColor

app:strokeColor="@null"