TextInputLayout: RuntimeException - Failed to resolve attribute at index 24
Asked Answered
V

2

23

I keep on getting this error when I try to setErrorEnabled on my textInputLayout :

03-12 12:29:03.206 5706-5706/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.myapp, PID: 5706
                                                 java.lang.RuntimeException: Failed to resolve attribute at index 24
                                                     at android.content.res.TypedArray.getColor(TypedArray.java:401)
                                                     at android.widget.TextView.<init>(TextView.java:696)
                                                     at android.widget.TextView.<init>(TextView.java:632)
                                                     at android.widget.TextView.<init>(TextView.java:628)
                                                     at android.widget.TextView.<init>(TextView.java:624)
                                                     at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
                                                     at com.bekwaai.popupwindow.RGNamePopUp$1.onClick(RGNamePopUp.java:48)
                                                     at android.view.View.performClick(View.java:4780)
                                                     at android.view.View$PerformClick.run(View.java:19866)
                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:135)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

This is the scenario - I have a textInputLayout inside a popupwindow. This is the code inside the popupwidow.

public class NamePopUp extends PopupWindow {

    android.support.v7.widget.AppCompatEditText name;
    TextInputLayout nameInput;


    public NamePopUp(final Context context) {
        super(context);
        View popupView = LayoutInflater.from(context).inflate(R.layout.popup_rg_confirm, null);
        nameInput = (TextInputLayout) popupView.findViewById(R.id.name_input_layout);
    }
}

This is my xml for the popupwindow layout:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:theme="@style/TextLabel"
    app:backgroundTint="@color/white"
    app:rippleColor="@color/white"
    android:id="@+id/name_input_layout"
    android:layout_marginBottom="8dp"
    android:paddingRight="24dp"
    android:paddingLeft="24dp">

<android.support.v7.widget.AppCompatEditText
    android:id="@+id/enter_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:textCursorDrawable="@drawable/color_cursor"
    android:hint="@string/groupname"/>

</android.support.design.widget.TextInputLayout>

This is the style I'm using:

<style name="TextLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textSize">20sp</item>
    <item name="android:textColorHint">@color/white</item>
    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@color/white</item>
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/white</item>
</style>

The popupwindow is called inside a android.support.v4.app.Fragment and the fragment is inside a AppCompatActivity.

The error occurs here when the user clicks the ok button but the name edittext is blank. In other words, the user has not entered anything in the edittext and have clicked ok:

    button_ok.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (StringUtils.isNotEmpty(name.getText().toString())) {
                nameInput.setErrorEnabled(false);
                groupNameEvent.doEvent(name.getText().toString());

            } else {
                nameInput.setErrorEnabled(true); //ERROR OCCURS HERE!
                nameInput.setError(context.getString(R.string.no_name));
            }
        }
    });

How do I get this error to disappear?

Vociferant answered 12/3, 2016 at 10:41 Comment(3)
Same thing happening to me :-(Khaki
My advice is not to use popupwindows at all. They are inflexible and do not work well with api 23. See this thread. #36093754 Use dialogActivity instead. The error will go away.Vociferant
Try this: https://mcmap.net/q/584370/-runtimeexception-while-using-new-textinputlayout-from-support-design-libraryGormandize
M
61

Just change the base theme for TextLabel to Widget.Design.TextInputLayout

<style name="TextLabel" parent="Widget.Design.TextInputLayout">
Missis answered 19/4, 2016 at 13:10 Comment(2)
Sorry I have a typo, it is TextInputLayout instead of TextInputLayouta. :)Missis
I have added the android:theme="@style/TextLabel" to my TextInputLayout but it is not working, what else I have to do? :(Claviform
S
3

For me a following works (https://mcmap.net/q/584370/-runtimeexception-while-using-new-textinputlayout-from-support-design-library):

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="textColorError">@color/design_textinput_error_color_light</item>
</style>
Spoliate answered 30/8, 2017 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.