17

I am seeing this error in a live app thus I have no clue why this happening. All I have is this exception log (see below). At first, I thought I applied style editTextBackgroungWhite(see below)to the editText inside my XML but removing it has no effect on the problem.

I'll be glad if someone could guide me towards the right direction.

P.S I am not able to replicate this bug on my device seems that it's a problem with some Samsung note series device only.

 <style name="editTextBackgWhite"parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">#ffffff</item>
    <item name="colorControlActivated">#ffffff</item>
    <item name="colorControlHighlight">#ffffff</item>
</style>


Fatal Exception: java.lang.UnsupportedOperationException: Failed to     resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
   at android.content.res.TypedArray.getColorStateList(TypedArray.java:484)
   at android.text.style.TextAppearanceSpan.(TextAppearanceSpan.java)
   at android.text.style.TextAppearanceSpan.(TextAppearanceSpan.java)
   at android.widget.Editor$SuggestionsPopupWindow$SuggestionInfo.(Editor.java)
   at android.widget.Editor$SuggestionsPopupWindow$SuggestionInfo.(Editor.java)
   at android.widget.Editor$SuggestionsPopupWindow.initContentView(Editor.java:2995)
   at android.widget.Editor$PinnedPopupWindow.(Editor.java)
   at android.widget.Editor$SuggestionsPopupWindow.(Editor.java)
   at android.widget.Editor.showSuggestions(Editor.java:2229)
   at android.widget.Editor$2.run(Editor.java:2109)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:158)
   at android.app.ActivityThread.main(ActivityThread.java:7225)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Sandeep Gahlawat
  • 217
  • 1
  • 3
  • 5

6 Answers6

14

The main cause of this problem seems to be a missing style/theme in the AppCompat library, or a bug in the library. It happens when using either AppCompatEditText or AppCompatAutoCompleteTextView and a WebView is also added to the layout (AdMob ads are WebViews). It happens on several versions of AppCompat, like 23, 24, 25, 26.

It can be seen more clearly in a useful demo app that someone made on Github:

  1. Clone the repo and open in Android Studio v2.3 or higher.
  2. Android Studio should prompt to update the gradle dependencies and buildToolsVersion in this project, something like this:

build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    ...
}

app/build.gradle:

buildToolsVersion '25.0.0'

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
  1. Update the dependencies then build the project. Run the app on Android 7 emulator or device, with a stock Android keyboard. Set the system language to English.
  2. On the input field, type the letters 'tttf' on the Android keyboard. Then press space. The word should be underlined as misspelled.
  3. Now click one of the letters (not long-press) to try to move the cursor. It should crash the app - like this:

Video screenshot example of the app crash

The solution (from here) is to explicitly add both "colorAccent" and "android:colorAccent" in your main AppTheme, in styles.xml:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
</style>

or

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
</style>

This will now work to allow the stock spelling suggestions popup to appear, and no more crashing.

Similar reports or duplicates:

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
  • Another idea that worked for me: add `android:textAppearance="@color/whatever"` to the layout for the suggestion items. this layout can be set with `edtitext.setAdapter(arrayadapter)` where ArrayAdapter will be constructed using a layout you made as the "resource" (see https://developer.android.com/reference/android/widget/ArrayAdapter) – fattire Feb 18 '20 at 00:20
5

Had exact same exception while using AutoCompleteTextView. Replication was really tough and wasted my two days in this.

The cause for this is Google spell checker popup, enabled in some devices which causes red line under words in Edittext/AutoCompleteEdittext and clicking on it opens a popup of spell suggestions. According to my observations this popup doesn't go too well in TextInputLayout(with style) and causes crash in some devices (in my case it was Moto G play). You can verify it by turning off the Google spell checker and it will work fine. But the real solution is to add

android:inputType="textNoSuggestions"

to your edittext in XML

This disables the spell checker for that edittext and rest works fine.

Let me know if it helped.

Abhinav Pawar
  • 421
  • 3
  • 12
  • 2
    Your comment really helped me with this issue, but after adding the textNoSuggestions it was still crashing. I fixed it adding: `android:inputType="textNoSuggestions|textVisiblePassword"` – Juanvi Martinez Aug 15 '17 at 14:19
2

After receiving this:

Non-fatal Exception: android.view.InflateException: Binary XML file line #16 in letstwinkle.com.twinkle:layout/tsnackbar_layout: Binary XML file line #16 in letstwinkle.com.twinkle:layout/tsnackbar_layout: Error inflating class com.androidadvance.topsnackbar.TSnackbar$SnackbarLayout

... multiple intermediates ...
Caused by java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0400c6 a=-1}
   at android.content.res.TypedArray.getColorStateList(TypedArray.java:675)
   at android.widget.TextView.readTextAppearance(TextView.java:4035)
   at android.widget.TextView.<init>(TextView.java:1104)
   at android.widget.Button.<init>(Button.java:166)
   at android.widget.Button.<init>(Button.java:141)
   at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:74)
   at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:224)
   at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:220)
   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
   at android.view.LayoutInflater.createView(LayoutInflater.java:864)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1016)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:666)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
   at com.androidadvance.topsnackbar.TSnackbar$SnackbarLayout.<init>(TSnackbar.java:633)
   at java.lang.reflect.Constructor.newInstance0(Constructor.java)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
   at android.view.LayoutInflater.createView(LayoutInflater.java:864)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1016)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:669)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
   at com.androidadvance.topsnackbar.TSnackbar.<init>(TSnackbar.java:130)
   at com.androidadvance.topsnackbar.TSnackbar.make(TSnackbar.java:137)
   at letstwinkle.com.twinkle.TopSnackbarReceiver.onReceive(TopSnackbarReceiver.java:26)
   at android.app.ActivityThread.handleReceiver(ActivityThread.java:4349)
   at android.app.ActivityThread.access$2500(ActivityThread.java:296)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2238)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:213)
   at android.app.ActivityThread.main(ActivityThread.java:8178)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

After much investigation, I found that the cause was using colorAccent as an attribute (?attr/).

<com.google.android.material.button.MaterialButton
    ...
    android:textColor="?attr/colorAccent"
    tools:text="Action"/>

I did declare the colorAccent in my theme:

<item name="colorAccent">@color/colorAccent</item>

but my theme inherits Theme.MaterialComponents.Light.DarkActionBar.Bridge, I wonder if that has something to do with it. Everywhere else in my layouts, I just use @color/colorAccent.

androidguy
  • 3,005
  • 2
  • 27
  • 38
1

It's 2021 and this error still persists on android N. As of my layout I was using the xml below.

<androidx.appcompat.widget.AppCompatEditText
            android:theme="@style/EditTextOnWhiteBgr"
            ...
/>

Where my EditTextOnWhiteBgr theme was set like this (styles.xml):

<style name="EditTextOnWhiteBgr" parent="@android:style/TextAppearance">
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:colorAccent">@color/colorPrimary</item>
</style>

After some investigation, as the exception is thrown with Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}, I figured out it refers to <public type="attr" name="textColorLink" id="0x0101009b" />.

I solved the problem by adding the attribute to my EditText's theme like this:

<style name="EditTextOnWhiteBgr" parent="@android:style/TextAppearance">
    <!-- ... -->
    <item name="android:textColorLink">@color/colorPrimary</item>
    <!-- ... -->
</style>
Ion Farima
  • 309
  • 1
  • 4
  • 12
1

I ran into a similar problem so I landed to this question. Here is how I found out what is going on. At first my StackTrace:

android.view.InflateException: Binary XML file line #95 in my.app:layout/abc_alert_dialog_material: Binary XML file line #37 in my.app:layout/abc_alert_dialog_button_bar_material: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #37 in my.app:layout/abc_alert_dialog_button_bar_material: Error inflating class Button
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 16: TypedValue{t=0x2/d=0x7f040314 a=7}
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:596)
    at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:76)
    at com.google.android.material.button.MaterialButtonHelper.loadFromAttributes(MaterialButtonHelper.java:109)
    at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:249)
    at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:220)
    ...

I my case something with a ColorStateList crashed. Here is the code around line 109 in MaterialButtonHelper.java:

rippleColor =
    MaterialResources.getColorStateList(
        materialButton.getContext(), attributes, R.styleable.MaterialButton_rippleColor);

So the lib is trying to load an attribute with the name rippleColor. Nothing special here byside that I defined for my app an attribute with the same name. The type of that resource is in my theme color. So this is the source of the crash. I will need to rename that attribute and this crash should be gone.

rekire
  • 47,260
  • 30
  • 167
  • 264
0

according to the answer of @Abhinav Pawar, I used

android:inputType="textAutoCorrect"

instead of

android:inputType="textNoSuggestions"

In fact, textNoSuggestions remove all suggested words by the keyboard at typing. While textAutoCorrect replace the wrong word by the good one. And the user is free to use the one he wants.

Coccoonx
  • 21
  • 1
  • 8