我的應用程序旨在讓用戶拍照並將其上傳到他們的Facebook牆上。下面的代碼非常相似,就有關此相同的問題等做題給定的工作代碼許多其他的例子,但仍然給我的空指針異常:空指針將圖片發佈到Facebook牆上時出現異常(android)
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();
}
}
我只想得到圖片上傳在我可以繼續添加消息之前進行工作。有任何想法嗎?
編輯: 這裏是與AsyncRunner(...)行雲的SampleUploadListener():
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)
待辦事項你有一張圖片需要加載?當'Object'被調用的時候''NullPointerException''通常被拋出,而'NullPointerException'不應該被'null'拋出時被拋出。 –
哪一行(請諮詢LogCat或發佈)? –
@Yawus:'byteArray'是我已經處理過的位圖中的一個字節數組。我檢查了它是否爲空,而不是。 –