12

It's a very strange Xiaomi device's OS exception. Even if I do have logs available from Fabric, the stack trace doesn't refer any of my code.

A crash details are below as reported in crashalytics(Fabric),

  • 21K crashes

  • All crashes on Xiaomi devices

  • Crashes on Android OS version 6, 7 and 8

Crash Log:

# OS Version: 8.1.0
# Device: Redmi Note 5 pro
# RAM Free: 30.1%
# Disk Free: 74.2%

#0. Crashed: main
       at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
       at android.widget.Editor.performLongClick(Editor.java:1205)
       at android.widget.TextView.performLongClick(TextView.java:10908)
       at android.view.View.performLongClick(View.java:6360)
       at android.view.View$CheckForLongPress.run(View.java:24768)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:171)
       at android.app.ActivityThread.main(ActivityThread.java:6606)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

--

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference
       at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
       at android.widget.Editor.performLongClick(Editor.java:1205)
       at android.widget.TextView.performLongClick(TextView.java:10908)
       at android.view.View.performLongClick(View.java:6360)
       at android.view.View$CheckForLongPress.run(View.java:24768)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:171)
       at android.app.ActivityThread.main(ActivityThread.java:6606)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

#0. Crashed: main
       at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
       at android.widget.Editor.performLongClick(Editor.java:1205)
       at android.widget.TextView.performLongClick(TextView.java:10908)
       at android.view.View.performLongClick(View.java:6360)
       at android.view.View$CheckForLongPress.run(View.java:24768)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:171)
       at android.app.ActivityThread.main(ActivityThread.java:6606)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Similar Reference:

https://issuetracker.google.com/issues/37127697

java.lang.NullPointerException with Nougat

Also asked on Xiaomi official forum http://en.miui.com/forum.php?mod=viewthread&tid=4595164

Please do provide any working solution as soon as possible. As users must not be happy with these crashes.

Thanks in advance.

Chitrang
  • 5,097
  • 1
  • 35
  • 58

4 Answers4

9

1)  First of all, only if required, set one of these.

textView.setMovementMethod(LinkMovementMethod.getInstance());

or 

setAutoLinkMask(Linkify.ALL);

or

Linkify.addLinks(textView, Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.MAP_ADDRESSES);

2) Secondly, set a long click listener for TextView and it must return true.

textView.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // do soemthing if needed
        return true;
    }
});

There is some internal crashing issue on Xiaomi devices. If you override setOnLongClickListener(reference) first and then follow the step one, it will use internal implementation and that will keep on crashing. So it is import to follow above steps in sequence.

I am open to other solutions, however by following this approach I don't see crash reports anymore.

Chitrang
  • 5,097
  • 1
  • 35
  • 58
3

Do you have a custom TextView in your app? Is it perhaps resizeable or has additional functionality?

Xiaomi's Android skin is likely interfering with that, and causing crashes. I suggest trying to long click all TextViews in your app.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
0

It happen when user doing long click on all selected text. Just define longClickListener:

edit_text.setOnLongClickListener {
   doSomething()
   true
}

and later you can remove it

edit_text.setOnLongClickListener(null)
mepfic
  • 19
  • 1
0

For me this crash happened when TextView contained link and setAutoLinkMask(Linkify.ALL); was called for the view. In this case Android handles all clicks (including long clicks) by this view. On devices of other brands link was opened after long click, but on Xiaomi device crash happened. It seems, that they have a bit different logic of handling onTouchEvent inside the TextView. I've played a bit around and found, that setting android:textIsSelectable="false" for the TextView in layout file solves the problem.

I know, that it's not scalable solution, but for my case it was perfect, so I stopped investigating further. Maybe it will give a hint to someone else.

Nobodyhave
  • 66
  • 4