facebook-android-sdk icon indicating copy to clipboard operation
facebook-android-sdk copied to clipboard

NullPointerException on GraphAction publish

Open joseprl89 opened this issue 12 years ago • 2 comments

Hi,

I've noticed an error when trying to create a graph object action.

I've used the code as provided by developer.facebook.com:


Bundle params = new Bundle(); params.putString("XXXX", "http://samples.ogp.me/XXXXXXXXXXXXXX");

Request request = new Request( Session.getActiveSession(), "me/XXXXXXXXXXXXXX", params, HttpMethod.POST ); Response response = request.executeAndWait(); // handle the response


And obtained a weird response with httpCode:-1 and a NullPointerException inside the cause.

I debugged a little bit inside the SDK code (not much) and found this stack trace:


06-20 13:07:12.526: W/System.err(15280): java.lang.NullPointerException 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.serializeToUrlConnection(Request.java:2008) 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.toHttpConnection(Request.java:1418) 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.executeBatchAndWait(Request.java:1512) 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.executeBatchAndWait(Request.java:1488) 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.executeBatchAndWait(Request.java:1470) 06-20 13:07:12.526: W/System.err(15280): at com.facebook.Request.executeAndWait(Request.java:1442) 06-20 13:07:12.536: W/System.err(15280): at com.facebook.Request.executeAndWait(Request.java:1324)


It seems that an outputstream is null when trying to close it.

I am not sure whether it I've been doing something wrong or if it an actual issue, but just letting you guys know.

Cheers,

Josep

joseprl89 avatar Jun 20 '14 11:06 joseprl89

Hi Josep,

I was able to reproduce the issue and added a check for when the OutputStream is null. This should be out in the next sdk release.

However, the problem beneath the surface seems to be that you are trying to run executeAndWait() in the main thread which produces a NetworkOnMainThreadException. Can you confirm that you were not running this method asynchronously and if you do create an async task, this exception doesn't happen and you get a proper http response?

Here's an example of your code in an async task.

        AsyncTask task = new AsyncTask() {
            @Override
            protected Response doInBackground(Void... voids) {
                Bundle params = new Bundle();
                params.putString("XXXX", "http://samples.ogp.me/XXXXXXXXXXXXXX");
                Request request = new Request(
                        Session.getActiveSession(),
                        "me/XXXXXXXXXXXXXX",
                        params,
                        HttpMethod.POST
                );
                return request.executeAndWait();
            }
            @Override
            protected void onPostExecute(Response response) {
                // handle the response
            }
        };
        task.execute();

Thanks, Sumin

suminkang avatar Sep 05 '14 20:09 suminkang

This issue was fixed in the 3.19 release. If the upgrade doesn't fix your problem, please open a bug at https://developers.facebook.com/bugs

gcaglar avatar Oct 22 '14 18:10 gcaglar