10

我将手机从 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" />

您能否告知为什么会发生这种情况以及我该如何解决?

先感谢您!!!

4

3 回答 3

12

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

旧代码

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

固定代码:

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

自动填充框架不再出现错误。我建议您检查一下您是否没有犯过类似的错误,误用了 Context。

于 2018-01-05T12:33:25.443 回答
6

对我来说,这似乎是一个直接的回归错误。通过在 Activity.onCreate 中执行此操作,我采取了最务实的方法:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
  getWindow().getDecorView().setImportantForAutofill(
      View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
于 2017-12-18T17:04:11.980 回答
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.
于 2020-02-12T10:54:38.870 回答