Search code examples
javaandroidandroid-textinputlayout

java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 on setErrorEnabled for InputTextLayout


I have a TextInputLayout:

<android.support.design.widget.TextInputLayout
    android:id="@+id/passwordLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="#FFF"
    android:theme="@style/TextInputLayoutWhite"
    app:errorTextAppearance="@style/ErrorText"
    app:hintTextAppearance="@style/TextInputLayoutWhite">

    <EditText
        android:id="@+id/passwordInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:imeOptions="actionGo"
        android:singleLine="true"
        android:textColor="#FFF"
        app:theme="@style/WhiteEditText">

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

and I am setting an error in my Activity like so:

passwordLayout.setErrorEnabled(true);

And this is throwing java.lang.UnsupportedOperationException: Can't convert to color: type=0x2

If I set app:errorEnabled on the TextInputLayout in my xml layout, the error text does show up, however I don't want it "enabled" at all times because it adds extra space for the textview which is unnecessary until I need to display the error.

Any ideas why this is throwing java.lang.UnsupportedOperationException? Here is the full stack trace:

03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x01010099
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009a
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009b
03-16 19:31:22.078 32577-32577/com.example.myapp W/System.err: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at android.content.res.TypedArray.getColor(TypedArray.java:326)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at android.widget.TextView.<init>(TextView.java:635)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at android.widget.TextView.<init>(TextView.java:578)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at android.widget.TextView.<init>(TextView.java:574)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at com.example.myapp.fragment.LoginFragment.onLoginFailure(LoginFragment.java:86)
03-16 19:31:22.086 32577-32577/com.example.myapp W/System.err:     at com.example.myapp.service.AccountService$1.onResponse(AccountService.java:31)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at com.example.myapp.service.AccountService$1.onResponse(AccountService.java:25)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at android.os.Handler.handleCallback(Handler.java:725)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:92)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at android.os.Looper.loop(Looper.java:137)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at java.lang.reflect.Method.invoke(Method.java:511)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-16 19:31:22.094 32577-32577/com.example.myapp W/System.err:     at dalvik.system.NativeStart.main(Native Method)

UPDATE

Here is what is in my ErrorText style. Please note the above error is thrown even when I don't set a theme:

<style name="ErrorText" parent="TextAppearance.AppCompat.Small">
    <item name="android:textColor">#FFF</item>
</style>

And here is the declaration of my passwordLayout:

TextInputLayout passwordLayout = (TextInputLayout) view.findViewById(R.id.passwordLayout);


Solution

  • this answer shows the problem is with your android:theme="@style/TextLabelWhite". Remove this or apply to style to your parent AppTheme.