Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook sharing causes android crash: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference #1095

Closed
tommulkins opened this issue Apr 23, 2020 · 13 comments
Milestone

Comments

@tommulkins
Copy link

The error encountered when testing a production build(curious, not emulator) of an apk targeting API 28 returns the following exception when attempting to shareViaFacebook:

FATAL EXCEPTION: pool-2-thread-1
    Process: us.worthy.worthy, PID: 8401
    java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at nl.xservices.plugins.SocialSharing$2.run(SocialSharing.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
@EddyVerbruggen
Copy link
Owner

Not sure why that's an issue all of the sudden, but please try passing in an empty array to the 'files' property (it's probably 'null' now).

@tommulkins
Copy link
Author

Thanks for that Eddy. Using the example from the readme I was using
window.plugins.socialsharing.shareViaFacebook('My message', null, 'https://my.url')

Changed it to
window.plugins.socialsharing.shareViaFacebook('My message', [], 'https://my.url')

Still the same problem.

java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at nl.xservices.plugins.SocialSharing$2.run(SocialSharing.java:271)

I think the second argument is meant for images and perhaps shareViaFacebook method doesn't have a parameter for files?

@tommulkins
Copy link
Author

Maybe this commit is the culprit? 2d2c5cd

@devVenus1202
Copy link

I also got the same issue.

@tommulkins
Copy link
Author

In case anyone else is looking to solve this for recent APIs of Android I fixed using the following:

Just for Android

window.plugins.socialsharing.shareVia('com.facebook.katana', 'My message', null, null, 'http://my.url');

It appears any of the other methods of sharing directly to Facebook inject an error atm.

@spinninghamster
Copy link

I am using Android target level 29 with window.plugins.socialsharing.shareWithOptions and I am NOT experiencing this problem.

@bongtawo
Copy link

I am using method ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT with this plugin.
android null object problem line 93 in android src file.
so i chaged 'null' to new JSONArray() like below.

from
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.isNull(3) ? args.getJSONArray(2) : null, args.getString(3), "com.facebook.katana", null, false, true, "com.facebook.composer.shareintent");

to
return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.isNull(3) ? args.getJSONArray(2) : new JSONArray(), args.getString(3), "com.facebook.katana", null, false, true, "com.facebook.composer.shareintent");

EddyVerbruggen added a commit that referenced this issue Aug 31, 2020
…od 'int org.json.JSONArray.length()' on a null object reference #1095
@EddyVerbruggen EddyVerbruggen added this to the 6.0.2 milestone Aug 31, 2020
@eweap
Copy link

eweap commented Sep 1, 2020

@EddyVerbruggen it seems to be fixed on master ! Thanks !

@ThangD
Copy link

ThangD commented Sep 9, 2020

@EddyVerbruggen when 6.0.2 release, thanks.

@EddyVerbruggen
Copy link
Owner

@ThangD It's on npm now.

@robvandijk
Copy link

Can this be added for 5.6.8 as well? We are experiencing the same crash but cannot update yet to 6.0.2.

@EddyVerbruggen
Copy link
Owner

@robvandijk 5.6.8 has been published, but 5.6.9 would be possible if you can create a PR.

@robvandijk
Copy link

PR just created, thanks for looking into this.

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

No branches or pull requests

8 participants