Skip to content

NullPointerException ClipboardManager.getAddPrimaryClipChangedListener() #1440

Closed

Description

@prat96
  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: [Ubuntu 18.04 LTS]
  • scrcpy version: [v1.14]
  • installation method: [snap]
  • device model: Custom Android device running Snapdragon 210
  • Android version: [v6.0.1]

Describe the bug
Crash on opening Scrcpy after snap updated it to v1.14.
I understand that older Android devices are not supported, but this device was working perfectly until scrcpy v1.13.
Tried using scrcpy -m 800/1080/1920, etc. as suggested for this issue in countless older threads
but this doesn't work.
Tried changing to lower bitrate as well scrcpy -b 1M/2M but to no avail.

On errors, please provide the output of the console (and adb logcat if relevant).

INFO: scrcpy 1.14 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed. 1.0 MB/s (33142 bytes in 0.033s)
[server] INFO: Device: **Redacted** (Android 6.0.1)
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getAddPrimaryClipChangedListener(ClipboardManager.java:99)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.addPrimaryClipChangedListener(ClipboardManager.java:111)
	at com.genymobile.scrcpy.Device.<init>(Device.java:83)
	at com.genymobile.scrcpy.Server.scrcpy(Server.java:23)
	at com.genymobile.scrcpy.Server.main(Server.java:225)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:251)

I've downgraded scrcpy to v1.12-1-g71df317 via channel 'edge' and it's working fine now.
Even if this issue is not resolved, I request the devs to keep older versions v1.12 or v1.13 available via snap channels for easy downgrade.

Activity

  1. changed the title [-]Error: Exception on thread Thread [main, 5, main][/-] [+]NullPointerException ClipboardManager.getAddPrimaryClipChangedListener()[/+] on May 28, 2020
  2. rom1v commented on May 28, 2020

    @rom1v
    Collaborator
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    	at com.genymobile.scrcpy.wrappers.ClipboardManager.getAddPrimaryClipChangedListener(ClipboardManager.java:99)
    

    Wow, that manager is null, it's weird.

    On v1.13, what happens if you Ctrl+c or Ctrl+Shift+v?

  3. prat96 commented on May 28, 2020

    @prat96
    Author

    On v1.13, if I Ctrl+C it just exits back to terminal stdin. No more output from scrcpy or anything like that.

  4. rom1v commented on May 28, 2020

    @rom1v
    Collaborator

    On v1.13, if I Ctrl+C it just exits back to terminal stdin.

    I mean Ctrl+c in the scrcpy window (not in the terminal).

  5. prat96 commented on May 28, 2020

    @prat96
    Author

    Oh! My bad. So I get this error on doing Ctrl+C in the scrcpy window;

    INFO: scrcpy 1.13 <https://github.com/Genymobile/scrcpy>
    /usr/local/share/scrcpy/scrcpy-server:...shed. 0.6 MB/s (27694 bytes in 0.042s)
    [server] INFO: Device: *Redacted* (Android 6.0.1)
    INFO: Renderer: opengl
    INFO: OpenGL version: 3.0 Mesa 19.2.8
    INFO: Trilinear filtering enabled
    INFO: Initial texture: 720x480
    [server] ERROR: Exception on thread Thread[Thread-10,5,main]
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    	at com.genymobile.scrcpy.wrappers.ClipboardManager.getGetPrimaryClipMethod(ClipboardManager.java:28)
    	at com.genymobile.scrcpy.wrappers.ClipboardManager.getText(ClipboardManager.java:65)
    	at com.genymobile.scrcpy.Device.getClipboardText(Device.java:153)
    	at com.genymobile.scrcpy.Controller.handleEvent(Controller.java:109)
    	at com.genymobile.scrcpy.Controller.control(Controller.java:66)
    	at com.genymobile.scrcpy.Server$1.run(Server.java:48)
    	at java.lang.Thread.run(Thread.java:818)
    
  6. prat96 commented on May 28, 2020

    @prat96
    Author

    Side note: After doing Ctrl+C, the scrcpy window is unresponsive. I am able to see the live stream but cannot control my device through scrcpy anymore.

  7. rom1v commented on May 28, 2020

    @rom1v
    Collaborator

    OK, so we can't retrieve the ClipboardManager. Which device is it? Is it a specific ROM?

  8. prat96 commented on May 28, 2020

    @prat96
    Author

    This is a custom Android product (not a phone).
    This is running Android v6.0.1 API 23. I can confirm that we have not removed the ClipboardManager service from our custom AOSP build.

  9. rom1v commented on May 28, 2020

    @rom1v
    Collaborator

    OK, then please check how the clipboard manager is loaded by introspection:

    clipboardManager = new ClipboardManager(getService("clipboard", "android.content.IClipboard"));

    private IInterface getService(String service, String type) {
    try {
    IBinder binder = (IBinder) getServiceMethod.invoke(null, service);
    Method asInterfaceMethod = Class.forName(type + "$Stub").getMethod("asInterface", IBinder.class);
    return (IInterface) asInterfaceMethod.invoke(null, binder);
    } catch (Exception e) {
    throw new AssertionError(e);
    }
    }

    It might help to understand why it does not work on your product. In your case, the call to getService() returns null.

  10. prat96 commented on May 28, 2020

    @prat96
    Author

    Understood, thank you very much! I will get back to you ASAP.

  11. added a commit that references this issue on Jul 3, 2020
    f7d4b6d
  12. rom1v commented on Jul 3, 2020

    @rom1v
    Collaborator

    Could you try the clipboard_manager branch, please?

  13. prat96 commented on Jul 7, 2020

    @prat96
    Author

    Oh wow, yes will do! Thanks :)

  14. fudongbai commented on Jul 11, 2020

    @fudongbai

    The clipboard_manager branch is working for my android 5.1.1 device, which is rk322x based box

    [ro.build.id]: [LMY49F]
    [ro.build.version.release]: [5.1.1]
    [ro.build.flavor]: [rk322x_echo-user]
    [ro.build.version.security_patch]: [2016-04-01]
    

    thanks @rom1v

  15. prat96 commented on Jul 20, 2020

    @prat96
    Author

    @rom1v Apologies for the delay, do I need to build the server as well or can I use pre-built?

  16. rom1v commented on Jul 20, 2020

    @rom1v
    Collaborator

    You could test the version (with binaries provided) from #1598, it includes this change.

  17. prat96 commented on Jul 20, 2020

    @prat96
    Author

    Hey @rom1v, I have succesfully tested this binary and everything is working perfectly!
    I now get this beautiful warning: [server] WARN: No clipboard manager, copy-paste between device and computer will not work

    Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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