自动填充框架更新8.1导致EditText崩溃

时间:2017-12-12 00:48:46

标签: android android-layout android-edittext android-8.0-oreo android-8.1-oreo

我将手机从8.0更新到8.1,现在当我尝试在我的应用程序(使用API​​级别25构建)上点击任何EditText或com.rengwuxian.materialedittext.MaterialEditText时,我遇到了这个崩溃。

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)

布局如下:

 <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" />

你能告诉我为什么会发生这种情况以及如何解决这个问题吗?

提前谢谢!!!

3 个答案:

答案 0 :(得分:6)

我有类似的问题。在 Webview 中的字段上点击 EditText 时出现相同的错误。 在我的情况下,问题是在 attachBaseContext 方法中使用了错误的 Context

旧代码

override fun attachBaseContext(newBase: Context?) {
   super.attachBaseContext(applicationContext.createConfigurationContext(...))
}

固定代码:

override fun attachBaseContext(newBase: Context?) {
    super.attachBaseContext(newBase.createConfigurationContext(...))
}

自动填充框架不再出现错误。我建议检查一下你是否犯了类似的错误而错过了上下文。

答案 1 :(得分:3)

对我来说似乎是一个直接的回归错误。我在Activity.onCreate中采用了最实用的方法:

scaleBand

答案 2 :(得分:1)

我花时间在这个错误上:

Fatal Exception: java.lang.NullPointerException: activityToken
       at android.os.Parcel.readException + 2010(Parcel.java:2010)
       at android.os.Parcel.readException + 1950(Parcel.java:1950)
       at android.view.autofill.IAutoFillManager$Stub$Proxy.startSession + 397(IAutoFillManager.java:397)

解决方案:

android:importantForAutofill="no" in XML file in Edit Text.