问题
I updated my phone to 8.1 from 8.0 and now I am getting this crash when I am trying to tap any EditText or com.rengwuxian.materialedittext.MaterialEditText on my app (which is built with API Level 25).
FATAL EXCEPTION: main
java.lang.NullPointerException: activityToken
at android.os.Parcel.readException(Parcel.java:2010)
at android.os.Parcel.readException(Parcel.java:1950)
at android.view.autofill.IAutoFillManager$Stub$Proxy.startSession(IAutoFillManager.java:381)
at android.view.autofill.AutofillManager.startSessionLocked(AutofillManager.java:993)
at android.view.autofill.AutofillManager.notifyViewEntered(AutofillManager.java:595)
at android.view.autofill.AutofillManager.notifyViewEntered(AutofillManager.java:566)
at android.view.View.notifyEnterOrExitForAutoFillIfNeeded(View.java:6980)
at android.view.View.onFocusChanged(View.java:6966)
at android.widget.TextView.onFocusChanged(TextView.java:9606)
at android.view.View.handleFocusGainInternal(View.java:6631)
at android.view.View.requestFocusNoSearch(View.java:10868)
at android.view.View.requestFocus(View.java:10847)
at android.view.View.requestFocus(View.java:10814)
at android.view.View.requestFocus(View.java:10756)
at android.view.View.onTouchEvent(View.java:13018)
at android.widget.TextView.onTouchEvent(TextView.java:9665)
at com.rengwuxian.materialedittext.MaterialEditText.onTouchEvent(MaterialEditText.java:1501)
at android.view.View.dispatchTouchEvent(View.java:11776)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12015)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The layout is as follows:
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/usernameET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_xlarge"
android:layout_marginTop="@dimen/padding_large"
android:enabled="@{!loading}"
android:hint="@string/username"
android:inputType="text"
android:lines="1"
android:maxLength="50"
android:maxLines="1"
android:singleLine="true"
android:textSize="@dimen/text_normal"
app:met_accentTypeface="fonts/averta_bold.otf"
app:met_floatingLabel="highlight"
app:met_floatingLabelText="@string/username"
app:met_primaryColor="@color/text_dark"
app:met_textColor="@color/text_blue"
app:met_typeface="fonts/averta_regular.otf" />
Can you please advise why this is happening and how I can fix it?
Thank you in advance!!!
回答1:
I had similiar problem. Same error when tapping on EditText, on field in Webview. In my case the problem was using wrong Context within attachBaseContext method.
Old code
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(applicationContext.createConfigurationContext(...))
}
Fixed code:
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase.createConfigurationContext(...))
}
No more errors with Autofill framework. I suggest checking if you didn't make similar mistake missusing Context.
回答2:
Seems like a straight-up regression bug to me. I'm taking the most pragmatic approach possible by doing this in the Activity.onCreate:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
getWindow().getDecorView().setImportantForAutofill(
View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
来源:https://stackoverflow.com/questions/47763756/autofill-framework-updates-8-1-cause-crash-to-edittext