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 SO questions pertaining to this exact same problem, yet still gives me the null pointer exception:
private void postOnWall()
{
final String response = "";
try
{
Bundle params = new Bundle();
params.putString("message", getMessage());
params.putByteArray("picture", byteArray);
mAsyncRunner.request(me/feed, params, "POST", new SampleUploadListener(),
null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
I would simply like to get the image upload working before I can move on to adding the message with it. Any ideas?
EDIT: Here is the SampleUploadListener() that goes with the AsyncRunner(...) line:
public class SampleUploadListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
try {
// process the response here: (executed in background thread)
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String src = json.getString("src");
// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e) {
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
LogCat:
06-22 13:23:45.136: W/System.err(20667): java.lang.NullPointerException
06-22 13:23:45.136: W/System.err(20667): at com.uncc.cci.TrashPickup.TrashPickupActivity.postwall(TrashPickupActivity.java:475)
06-22 13:23:45.136: W/System.err(20667): at com.uncc.cci.TrashPickup.TrashPickupActivity$5$1.onClick(TrashPickupActivity.java:230)
06-22 13:23:45.140: W/System.err(20667): at android.view.View.performClick(View.java:3511)
06-22 13:23:45.140: W/System.err(20667): at android.view.View$PerformClick.run(View.java:14105)
06-22 13:23:45.140: W/System.err(20667): at android.os.Handler.handleCallback(Handler.java:605)
06-22 13:23:45.140: W/System.err(20667): at android.os.Handler.dispatchMessage(Handler.java:92)
06-22 13:23:45.140: W/System.err(20667): at android.os.Looper.loop(Looper.java:137)
06-22 13:23:45.140: W/System.err(20667): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-22 13:23:45.144: W/System.err(20667): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 13:23:45.144: W/System.err(20667): at java.lang.reflect.Method.invoke(Method.java:511)
06-22 13:23:45.144: W/System.err(20667): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-22 13:23:45.144: W/System.err(20667): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-22 13:23:45.148: W/System.err(20667): at dalvik.system.NativeStart.main(Native Method)