在活动中使用EditTexts更改片段时," java.lang.NullPointerException"发生(完整堆栈跟踪在下面)。这仅在调试模式下发生。我在网上搜索过,建议的解决方案是取消选中Advanced Profiling(< API 26)。但就我而言,该选项已取消选中,我的目标是API级别27。
有解决方法吗?
java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection()' on a null object reference
at android.view.inputmethod.InputConnectionWrapper.closeConnection(InputConnectionWrapper.java:270)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:541)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
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:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
环境:
compileSdkVersion 27
minSdkVersion 23
targetSdkVersion 27
buildToolsVersion "27.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Android Studio 3.1.1
Build #AI-173.4697961, built on April 4, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Android 8.1.0
加
我已将过滤器设置为"错误"所以我没有看到这些,但是当我把它改成" Verbose"时,我可以看到这些事情发生在崩溃之前,当我试图替换片段时。
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741873 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741875 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741874 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741876 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741877 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741878 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741879 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741891 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741880 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741881 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741882 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741883 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741884 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741885 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741886 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741887 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741888 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741889 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741890 isVisible=true
I/Choreographer: Skipped 104 frames! The application may be doing too much work on its main thread.
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741824 isVisible=false
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741825 isVisible=false
D/AndroidRuntime: Shutting down VM
我使用此代码将片段替换为另一个片段。
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.frame, Fragment2.newInstance());
transaction.commit()
已添加2。
如果我注释掉EditText,那么这次崩溃就不会发生。我认为这与AutoFill(Oreo)有关,所以我想通过创建一个可以重现这个问题的简单项目来解决这个问题,但不幸的是,我无法让AutoFill对它进行处理。我的原始项目自动启用了自动填充,因此我不确定它启用的条件。
已添加3。
它也发生在Android 7.1(模拟器)上。由于7.1没有自动填充,我认为它与自动填充无关。我需要进一步调查。