material-components / material-components/material-components-android

[ShapeableImageView] Crash occasionally

Open
#3,296 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: Shape Need more info
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**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
+ ", theme=" + mTheme);
}

**Minimal sample app repro:** use it in layout.xml for example:

**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](https://github.com/material-components/material-components-android/releases) of the library.

We also happily accept [pull requests](https://github.com/material-components/material-components-android/pulls).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal layout.xml reproduction using ShapeableImageView and the reported app:shapeAppearance value on Android API 33. Read the stack trace from the ShapeableImageView constructor through TypedArray color resolution; done means the sample inflates without the reported crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.