An Android screen crashes with UnsupportedOperationException: Failed to resolve attribute at index
Your error
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f0400f5 a=-1}2 more lines it can showFix it fast
Most common cause, 1 of 2The app theme does not define the attribute
Make the app theme inherit from a Material3 theme.
<!-- app/src/main/res/values/themes.xml -->
<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/brand</item>
</style>
<!-- or keep the parent and add what is missing -->
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimaryContainer">@color/brand_container</item>
</style>Short answer
UnsupportedOperationException: Failed to resolve attribute at index N, with TypedValue{t=0x2/d=0x7f...}, means a layout, style or drawable uses a ?attr/ reference that the theme of the inflating activity does not define. Type 0x2 is an unresolved theme attribute and d is its id. Look the id up with aapt2, then extend a Material3 theme or add the item.
Which cause do you have?
Take the hex number after d= in the exception. It is the resource id of the attribute the theme could not supply. Dump the debug APK's resource table with aapt2 and search for that id to get the attribute's name.
./gradlew :app:assembleDebug
"$ANDROID_HOME/build-tools/36.1.0/aapt2" dump resources app/build/outputs/apk/debug/app-debug.apk | grep -i "0x7f0400f5"Then find the line you see in this list and open its fix:
- 1The app theme does not define the attribute
aapt2 names a Material attribute such as colorPrimaryContainer or colorOnSurface, and the theme's parent is Theme.AppCompat or Theme.MaterialComponents - 2One activity overrides the app theme in the manifest
Only one screen crashes, and its activity entry in AndroidManifest.xml has its own android:theme, such as a splash, transparent or dialog theme
What does the error look like?
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f0400f5 a=-1}RuntimeException: Failed to resolve attribute at index 6The app crashes as soon as a layout is inflated, and the stack trace runs through TypedArray
Cause 1 of 2
The app theme does not define the attribute
You seeaapt2 names a Material attribute such as colorPrimaryContainer or colorOnSurface, and the theme's parent is Theme.AppCompat or Theme.MaterialComponents
Check
Failed to resolve attribute at index is thrown when a ?attr/ value is still a theme attribute reference (TypedValue type 0x2) after the theme was asked for it, which means the theme has no value for that attribute. The Material Components guide warns that an AppCompat or MaterialComponents theme lacks the newer Material3 attributes unless you add them yourself.
grep -n "parent=" app/src/main/res/values/themes.xmlFix
Make the app theme inherit from a Material3 theme. If the theme must stay on its old parent for now, add an item for each missing attribute instead.
<!-- app/src/main/res/values/themes.xml -->
<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/brand</item>
</style>
<!-- or keep the parent and add what is missing -->
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimaryContainer">@color/brand_container</item>
</style>Verify
Install the debug build and open the screen; no AndroidRuntime crash appears in logcat.
adb logcat -s AndroidRuntimeConfirmed by github.com
Cause 2 of 2
One activity overrides the app theme in the manifest
You seeOnly one screen crashes, and its activity entry in AndroidManifest.xml has its own android:theme, such as a splash, transparent or dialog theme
Check
Failed to resolve attribute at index on a single screen usually comes from that activity's own theme. An android:theme on an activity element sets the theme of that activity's context, and the application theme only applies when the activity sets none; a theme built on a bare platform parent does not carry the app's Material attributes.
grep -n "android:theme" app/src/main/AndroidManifest.xmlFix
Give that activity a theme that extends the app theme, so it inherits every attribute and changes only what it needs, or remove the override.
<!-- themes.xml -->
<style name="Theme.MyApp.Transparent" parent="Theme.MyApp">
<item name="android:windowIsTranslucent">true</item>
</style>
<!-- AndroidManifest.xml -->
<activity
android:name=".OverlayActivity"
android:theme="@style/Theme.MyApp.Transparent" />Verify
Open the screen again; it inflates, and logcat shows no new AndroidRuntime entry.
adb logcat -s AndroidRuntimeConfirmed by developer.android.com
How do I stop it coming back?
- Derive every activity, dialog and overlay theme from the app theme instead of from a platform theme.
- Move the app theme to a Material3 parent in one change, then add new Material widgets afterwards.
- Run an instrumentation or screenshot test that opens every screen, so a missing attribute fails CI instead of a user's device.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: QistLock, Nuclear Home Video.