Skip to content Skip to sidebar Skip to footer

Null Pointer Exception When Posting A Picture To Facebook Wall (android)

My app is meant to allow users to take a picture and then upload it to their Facebook wall. The following code is very similar to many other examples of working code given on other

Solution 1:

When you have corrected whatever bug you have here, you will unfortunately discover that it is not possible at this time to post an image to your wall by uploading the actual image bytes directly to facebook. You can upload a photo to their photos gallery, but not to their wall. To post a photo to the wall it must already reside online and you will need to provide a link to where it lives along with the other data. If I'm mistaken then this is a very new development as I just encountered all this a few months ago and even filed a bug with Facebook which they rejected saying that "it's not a bug, it's how we intended things to be".

If you're ok with putting the photo in their gallery (if it's the only photo IN the gallery it will look almost exactly like a regular wall post) this is the way to do it: Android post picture to Facebook wall

Solution 2:

Should be:

privatevoidpostOnWall() {
    Bundle params = new Bundle();            
    params.putString("message", "New picture");
    params.putByteArray("source", byteArray);
    mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null);
}

You sent the path as null and that's probably why you got the null pointer exception. Also according to the documentation the image parameter name is source.


Edit

Try this to check if mAsyncRunner is null:

privatevoidpostOnWall() {
    Bundle params = new Bundle();            
    params.putString("message", "New picture");
    params.putByteArray("source", byteArray);
    Log.d("Facebook-Example", mAsyncRunner == null ? "mAsyncRunner is null" : "mAsyncRunner not null");
    mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null);
}

Since the error is thrown in that line, it seems like the only possible thing.

Post a Comment for "Null Pointer Exception When Posting A Picture To Facebook Wall (android)"