InputConnection.finishComposingText() NullPointerException

2022-09-01 19:44:37

我在 crashlytics 上收到此错误日志。我不知道是什么让这次崩溃。它发生在Android 4.x,5.x,6.x设备上。(三星,索尼,LGE等)

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
   at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
   at android.view.inputmethod.InputMethodManager.checkFocusNoStartInput(InputMethodManager.java:1809)
   at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1761)
   at android.view.inputmethod.InputMethodManager.isActive(InputMethodManager.java:883)
   at android.widget.Editor$CursorAnchorInfoNotifier.updatePosition(Editor.java:4095)
   at android.widget.Editor$PositionListener.onPreDraw(Editor.java:2564)
   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1018)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2313)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1301)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7021)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
   at android.view.Choreographer.doCallbacks(Choreographer.java:590)
   at android.view.Choreographer.doFrame(Choreographer.java:560)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:145)
   at android.app.ActivityThread.main(ActivityThread.java:6918)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

答案 1

如此处所述,由于该工具,可能会发生这种情况。Android Advanced Profiling

从对话框中禁用它:Run/Debug Configurations

disabling advanced profiling


答案 2

确保输入连接在 onCreateInputConnection 重写方法中不为 null。

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
    if (inputConnection == null)
    {
        return null;
    }
    return new MyInputConnectionWrapper(inputConnection,
            true);
}

其中 MyInputConnectionWrapper 是您的自定义输入连接包装器,它是从 InputConnectionWrapper 扩展而来的。


推荐