我在SpannableStringInternal中的NPE的Crashlytics中收到错误报告,但无法在任何电话上重现该问题或确定其来源。我正在呼吁互联网帮助我确定潜在的问题。

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
   at android.text.SpannableStringInternal.hashCode(SpannableStringInternal.java:480)
   at android.text.SpannedString.hashCode(SpannedString.java)
   at java.util.Objects.hashCode(Objects.java:98)
   at android.view.inputmethod.CursorAnchorInfo.<init>(CursorAnchorInfo.java:435)
   at android.view.inputmethod.CursorAnchorInfo.<init>(CursorAnchorInfo.java)
   at android.view.inputmethod.CursorAnchorInfo$Builder.build(CursorAnchorInfo.java:391)
   at android.widget.Editor$CursorAnchorInfoNotifier.updatePosition(Editor.java:4390)
   at android.widget.Editor$PositionListener.onPreDraw(Editor.java:3250)
   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2492)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
   at android.view.Choreographer.doCallbacks(Choreographer.java:702)
   at android.view.Choreographer.doFrame(Choreographer.java:638)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
   at android.os.Handler.handleCallback(Handler.java:751)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6692)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

从源看来,某种程度上,游标/选择导致设置了空 Spanned 。

该错误仅在Android 7上发生:
android.widget.Editor : NullPointerException in SpannableStringInternal-LMLPHP

最佳答案

面临同样的问题。在我的情况下,这是由富文本解析器库cwac-richedit引起的。在将html解析为spannable时,女巫将设置为null Spanned 。这是fix

检查从何处获得设置为EditText的CharSequence,很有可能在此处的某个位置设置了空 Spanned 。
在我的情况下,设置这些范围的不是光标或选择。

10-08 05:19