7

This error seems to be happening only on Samsung phones using Android 6.0.1. or 7.0:

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void android.widget.Editor$SelectionModifierCursorController.hide()' on a null object reference
 
android.widget.Editor.performLongClick (Editor.java:1139)
 
android.widget.TextView.performLongClick (TextView.java:10945)
 
android.view.View$CheckForLongPress.run (View.java:22568)
 
android.os.Handler.handleCallback (Handler.java:739)
 
android.os.Handler.dispatchMessage (Handler.java:95)
 
android.os.Looper.loop (Looper.java:148)
 
android.app.ActivityThread.main (ActivityThread.java:7325)
 
java.lang.reflect.Method.invoke (Method.java)
 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
 
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)

Looking for a way to prevent it. =)

It seems it's a known issue, but with small priority:

Issue 228485: SelectionModifierCursorController.hide()' on a null object reference

Marilia
  • 1,911
  • 1
  • 19
  • 28
  • Any updates regarding this issue? – Laurent May 01 '17 at 19:30
  • This is an issue in the lib code. I can't replicate it but it appears in Crashlytics reports. The closest lead I got to something similar is this: http://stackoverflow.com/questions/37978026/java-lang-nullpointerexception-attempt-to-invoke-virtual-method-void-android-w Not exactly the same thing, but some similarities, like the Editor in Samsung phones causing null pointer exception on long click. The steps to replicate described there didn’t caused any problems on the Samsung (Android 6.0.1) we have here tho. – Marilia May 01 '17 at 21:10

1 Answers1

3

For me easiest solution was to override this methods in EditText. Hope Samsung will fix it one day.

override fun performLongClick(): Boolean {
    try {
        return super.performLongClick()
    } catch (e: NullPointerException) {
        return true
    }
}

override fun performLongClick(x: Float, y: Float): Boolean {
    try {
        return super.performLongClick(x, y)
    } catch (e: NullPointerException) {
        return true
    }
}
Nokuap
  • 2,289
  • 2
  • 17
  • 17