<android.support.design.widget.TextInputLayout
android:id="@+id/txtInputLayDateOfBirth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/txtDateOfBirth"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="6dp"
android:background="@drawable/drop_down"
android:clickable="true"
android:drawableRight="@drawable/ic_calendar"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:paddingRight="20dp"
android:hint="@string/dob"
android:textColorHint="@color/colorGray"
android:textColor="@color/colorWhite"/>
</android.support.design.widget.TextInputLayout>
当我跟随陈述时,它会给出错误
mDateOfBirthTextInputLayout.setError(error.getCollatedErrorMessage(mContext));
它在Android 4.4中运行良好,但在Android 5.1中出现错误
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sample, PID: 1824
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundTintList(android.content.res.ColorStateList)' on a null object reference
at android.support.v4.view.ViewCompatLollipop.setBackgroundTintList(ViewCompatLollipop.java:78)
at android.support.v4.view.ViewCompat$LollipopViewCompatImpl.setBackgroundTintList(ViewCompat.java:1602)
at android.support.v4.view.ViewCompat.setBackgroundTintList(ViewCompat.java:2893)
at android.support.design.widget.TextInputLayout.updateEditTextBackground(TextInputLayout.java:544)
at android.support.design.widget.TextInputLayout.setError(TextInputLayout.java:445)
at com.example.sample.ui.CompleteProfileFragment$RegistrationController.onValidationFailed(CompleteProfileFragment.java:390)
at com.mobsandgeeks.saripaar.Validator.triggerValidationListenerCallback(Validator.java:721)
at com.mobsandgeeks.saripaar.Validator.validateFieldsWithCallbackTill(Validator.java:697)
at com.mobsandgeeks.saripaar.Validator.validateUnorderedFieldsWithCallbackTill(Validator.java:679)
at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:334)
at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:295)
可能是什么错误? EditText
位于TextInputLayout
内时,不会出现错误。但是当TextView
放在其中时会出现错误。