Android.widget.Editor: NullPointerException in SpannableStringInternal

I get Crashlytics error reports for NPE in SpannableStringInternal, but I could not reproduce the problem on any phone or determine the source of it. I am calling for the Internet to help me identify the underlying problem.

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) 

From the source, it seems that somehow the cursor / selection is invoking a null Spans value.

Error only on Android 7: Alarm Device Information

+5
source share
1 answer

Faced the same problem. In my case, it was caused by a rich text parser lib cwac-richedit witch set zero spaces during parsing html to spannable. Here's a fix for it.

Check where you get the CharSequence that is set to EditText, it is very likely that the zero range is set somewhere there. In my case, it was not the cursor or selection that set these spaces.

0
source

Source: https://habr.com/ru/post/1273741/


All Articles