Skip to content

NullPointer exception happening within setNewPasteboardItem #1

Description

@pouwelsjochem

Our Google Play Console is reporting a null pointer exception that starts happening from Android 10 and up. This should be easy to fix.

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ClipData$Item android.content.ClipData.getItemAt(int)' on a null object reference
  at plugin.pasteboard.ClipboardListener.setNewPasteboardItem (ClipboardListener.java:31)
  at plugin.pasteboard.ClipboardListener.access$200 (ClipboardListener.java:18)
  at plugin.pasteboard.ClipboardListener$1.run (ClipboardListener.java:65)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8633)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)

Wrapping the this line and the next one in an if statement would solve the crash.

if (clipData != null && clipData.getItemCount() > 0) {
   android.content.ClipData.Item item = clipData.getItemAt(0);
   shared.setCurrentPasteboardItem(shared.ApiLevel11.coerceToString(context, item));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions