首页 > 解决方案 > 'void android.view.inputmethod.InputConnection.closeConnection()' 上的 NullPointerException

问题描述

我有一个有趣的问题。在 EditText 字段中输入文本后的片段中,我遇到了下一个异常:

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:105)
        at android.os.Looper.loop(Looper.java:251)
        at android.app.ActivityThread.main(ActivityThread.java:6572)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

只有在片段被破坏之后。并且这种情况出现在所有具有 EditText 的片段中。我认为有一些问题,InputMethodManager但如何解决它 - 不知道。值得注意的是,该问题并未出现在所有设备上。如果有人知道,会发生什么以及如何解决这个问题 - 请告诉我)谢谢。

标签: android

解决方案


转到Run -> Edit configuration settings -> Profiling -> Enable advanced profiling此将防止EditText崩溃。

同样的问题: InputConnection.finishComposingText() 方法中的空指针异常


推荐阅读