我一直在尋找發佈圖像在facebook上的牆壁,因爲早晨和谷歌搜索它,得到關於張貼的許多信息,但對我來說沒有運氣。我可以發佈鏈接沒有任何錯誤,但一旦我嘗試圖像獲取NullPointer異常在Facebook牆上張貼圖像
我的按鈕點擊事件監聽器即時通訊調用此方法後。如果我取消鏈接參數,然後它會顯示一個對話框,詢問份額和取消,如果我把這個params.putByteArray("picture", data);
代碼,我會得到下面的logcat錯誤
09-15 15:51:50.647: E/AndroidRuntime(9716): FATAL EXCEPTION: main
09-15 15:51:50.647: E/AndroidRuntime(9716): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.m2fpremiun.dressup/com.m2fpremiun.dressup.FBProjectActivity}: java.lang.NullPointerException
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2189)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2216)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread.access$600(ActivityThread.java:149)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.os.Handler.dispatchMessage(Handler.java:99)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.os.Looper.loop(Looper.java:153)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread.main(ActivityThread.java:5000)
09-15 15:51:50.647: E/AndroidRuntime(9716): at java.lang.reflect.Method.invokeNative(Native Method)
09-15 15:51:50.647: E/AndroidRuntime(9716): at java.lang.reflect.Method.invoke(Method.java:511)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
09-15 15:51:50.647: E/AndroidRuntime(9716): at dalvik.system.NativeStart.main(Native Method)
09-15 15:51:50.647: E/AndroidRuntime(9716): Caused by: java.lang.NullPointerException
09-15 15:51:50.647: E/AndroidRuntime(9716): at libcore.net.UriCodec.encode(UriCodec.java:132)
09-15 15:51:50.647: E/AndroidRuntime(9716): at java.net.URLEncoder.encode(URLEncoder.java:50)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.facebook.android.Util.encodeUrl(Util.java:85)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.facebook.android.Facebook.dialog(Facebook.java:774)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.m2fpremiun.dressup.FBProjectActivity.postToWall(FBProjectActivity.java:436)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.m2fpremiun.dressup.FBProjectActivity.loginToFacebook(FBProjectActivity.java:288)
09-15 15:51:50.647: E/AndroidRuntime(9716): at com.m2fpremiun.dressup.FBProjectActivity.onCreate(FBProjectActivity.java:83)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.Activity.performCreate(Activity.java:5020)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-15 15:51:50.647: E/AndroidRuntime(9716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
09-15 15:51:50.647: E/AndroidRuntime(9716): ... 11 more
請人幫助我獲得解決這個問題。
public void postToWall() {
// post on user's wall.
byte[] data = null;
Bundle params = new Bundle();
//postParams.putString("description","I'm playing JackPac and Scored "+hScore+" ! Can you beat my High Score?");
// postParams.putString("link", "https://play.google.com/store/apps/details?id=com.mobi2fun.jackpac&hl=en");
Bitmap bi = BitmapFactory.decodeFile("/storage/sdcard0/Game/test.png");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
params.putString("caption", "Image Post");
//params.putString("description","I'm playing XYZ Game and Scored "+hScore+" ! Can you beat my High Score?");
//params.putString("link", "https://play.google.com/store/apps/details?id=xyz.package&hl=en");
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
facebook.dialog(this, "feed",params, new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
logoutFromFacebook();
try {
//facebook.logout(getApplicationContext());
//facebook.setAccessExpires(0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCancel() {
logoutFromFacebook();
try {
// facebook.logout(getApplicationContext());
mAsyncRunner.logout(getApplicationContext(),new RequestListener() {
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
這些permisions我menifest文件給
我已經檢查這個環節,嘗試了所有codeBUT沒有運氣Facebook wall post with text and image Upload image to FaceBook from SDCard
檢查這一行了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.m2fpremiun.dressup/com.m2fpremiun.dressup.FBProjectActivity –
是的,我檢查了它,這是此行上的空指針異常params.putByteArray(「picture」,data);如果我刪除這條線,每一件事都會運行良好,但我需要在Facebook牆上發佈圖像 –