18

My app has been humming along nicely through various Android versions. I have users running it on Android 4.3, 5.0, 5.1 and 6.0 with no problems. However a user with a S7 Edge has just updated with Android 7.0 and the app is crashing when text is pasted into an EditText field (This is the first and only thing you do with this app - it starts you paste in text into a box and then the app parses the text).

I have looked at many threads on Null Pointer Exceptions and I have looked at the source for Editor.java but nothing is obvious. The stack trace below shows no problems with my code. Any ideas what they changed with 7.0 that could be causing this?

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.widget.Editor$SelectionModifierCursorController.isDragAcceleratorActive()' on a null object reference
at android.widget.Editor.updateFloatingToolbarVisibility(Editor.java:1520)
at android.widget.Editor.onTouchEvent(Editor.java:1475)
at android.widget.TextView.onTouchEvent(TextView.java:10024)
at android.view.View.dispatchTouchEvent(View.java:10725)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
at android.widget.ScrollView.dispatchTouchEvent(ScrollView.java:738)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:505)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1863)
at android.app.Activity.dispatchTouchEvent(Activity.java:3226)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:467)
at android.view.View.dispatchPointerEvent(View.java:10954)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5051)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4908)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4492)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4458)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4591)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4648)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4492)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4458)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4439)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6936)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6875)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6836)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7046)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7010)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7073)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:632)
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:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Zhao
  • 904
  • 1
  • 11
  • 34
Gavin
  • 460
  • 4
  • 11
  • Have you seen http://stackoverflow.com/questions/41687484/attempt-to-invoke-virtual-method-void-android-widget-editorselectionmodifiercu or http://stackoverflow.com/questions/37978026/java-lang-nullpointerexception-attempt-to-invoke-virtual-method-void-android-w – René Hoffmann Mar 21 '17 at 12:08
  • 2
    Looks like it is a known issue: https://code.google.com/p/android/issues/detail?id=228485 – René Hoffmann Mar 21 '17 at 12:10
  • Not exactly the same method crashing but that is partially helpful in that it isnt my app. However I would like to know how to get around it. As I said though my app isn't doing anything when they paste the text in :-( – Gavin Mar 21 '17 at 12:19
  • @Gavin: The cited bug and your crash are coming from Samsung devices. Can you reproduce your problem in the emulator, or in a non-Samsung Android 7.0+ environment? – CommonsWare Mar 22 '17 at 11:38
  • @CommonsWare I haven't had a chance to properly experiment in the emulator. I do see some other users are on Android 7 in the dashboard but I only have one user experiencing this problem at the moment and they advise the problem started after upgrading to Nougat. – Gavin Mar 25 '17 at 09:50
  • I have the same issue. It happens exclusively (but sporadically) on Samsung devices with Android 7.0. Never seen it in real life but there is a steady stream of crash reports coming in through HockeyApp. :/ – Matthias Schicker May 12 '17 at 19:10
  • We are having the same issue. Happens on multiple Samsung devices (S6, S7, Edge, Active, etc). And only on Android 7.0 – Zhao May 16 '17 at 20:52
  • I have not had any change in this issue. A user reported he found a workaround by pasting in via some other method but I don't have the details of how he got it to work. – Gavin May 18 '17 at 03:59
  • I have the same problem on Samsung S6 (Android 7.0) – Alireza Noorali Mar 03 '18 at 12:47
  • A user just reported to me that the Oreo update on his S8 has fixed this problem. – Gavin Apr 18 '18 at 10:30

3 Answers3

7

I resolved it by removing

MyEditText.setMovementMethod(new ScrollingMovementMethod());

5

This is how you block the copy paste menu from appearing in any way, shape or form. This bug really drove me crazy, and as with any Samsung bug you know its in their code but you also know they won't fix it any time soon. Anyways, here's wonder wall...

  1. Check if Android.Build.Model.toLowerCase().startsWith('sm-g930'). Do not match the whole string, the last letter is a minor version identifier. I stored this boolean in shouldBlockCopyPaste variable which comes up later.

  2. If it matches you want to block the copy paste menu from showing. This is how you ACTUALLY DO IT!!!

Override these 2 functions, you'll notice my shouldBlockCopyPaste boolean, this is so other devices dont get blocked.

   @Override
   public ActionMode StartActionMode (ActionMode.Callback callback){
      if (shouldBlockCopyPaste) {
        return null;
      } else {
        return super.StartActionMode(callback);
      }
    }

   @Override
   public ActionMode StartActionMode (ActionMode.Callback callback, int type){
      if (shouldBlockCopyPaste) {
        return null;
      } else {
        return super.StartActionMode(callback, type);
      }
    }
self.name
  • 2,341
  • 2
  • 17
  • 18
0

I've seen this crash for a while in my app coming from Samsung devices. turned out that a long press on a TextView brought up the copy-paste menu on those devices and the user was even able to paste text over (although its not an EditText component). Ended up disabling all types of interactions in the XML of the culprit TextViews (most importantly longClickable) and the crash wen't away.

 <TextView
...
    android:longClickable="false"
    android:clickable="false"
    android:linksClickable="false" />
N M
  • 1
  • 1
  • A user just reported to me that following the Oreo update on his S8 that this problem has disappeared. FYI. – Gavin Apr 18 '18 at 10:29