In our app we use EditText with TextInputLayout to show validation errors. Everything worked fine until we updated to latest support library com.android.support:design:23.2.0. After this update app started to crash when it tries to show error on . Layout:
<android.support.design.widget.TextInputLayout android:id="@+id/name_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:counterEnabled="true" app:counterMaxLength="100" > <EditText android:id="@+id/name_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/group_name" android:inputType="textMultiLine|textCapWords" android:textSize="16sp"/> </android.support.design.widget.TextInputLayout> Code:
nameLayout.setError("Error); nameEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { nameLayout.setError(null); } } }); Error:
FATAL EXCEPTION: main Process: im.grouvi.app.debug, PID: 10704 java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f01010b a=2} at android.content.res.TypedArray.getColorStateList(TypedArray.java:482) at android.widget.TextView.setTextAppearance(TextView.java:2757) at android.support.design.widget.TextInputLayout.updateCounter(TextInputLayout.java:681) at android.support.design.widget.TextInputLayout.access$300(TextInputLayout.java:82) at android.support.design.widget.TextInputLayout$1.afterTextChanged(TextInputLayout.java:242) at android.widget.TextView.sendAfterTextChanged(TextView.java:8004) at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:10165) at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1043) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:560) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:491) at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:685) at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:445) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) After more testing. It crashes only when it reaches input character maximum set in counterMaxLength
Version 23.2.0 of design library introduced Theme.Design.* family of themes which mirror a subset of AppCompat themes but define this attribute on top of it:
<item name="textColorError">@color/design_textinput_error_color_light</item> Either have your theme extend Theme.Design.* or copy the above line to your theme.
The textColorError attribute has to be defined in your theme in order to use error states in TextInputLayout. Otherwise it will crash just as you mentioned.
You can use your own error color value of course.
The default values are @color/design_textinput_error_color_light for light themes and @color/design_textinput_error_color_dark for dark themes.
If you're using support library version 26+ it looks like this
<item name="textColorError">?attr/colorError</item> for both light and dark themes.
Its a bug which has been already logged here. Its not solved till 23.2.1 design support library. https://code.google.com/p/android/issues/detail?id=202051
Meanwhile you can use the solution mentioned by @Eugen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With