我正在尝试使用facebook api将图片上传到Facebook。 但是得到错误请找到下面的代码。 我无法找出错误。我试过调试它但是无法理解查看log cat的错误。请高手帮忙。提前谢谢。
public void postImageonWall(Bitmap bmpImg) {
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmpImg.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
try {
facebook.request(params);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Log Cat:
05-30 05:55:52.489: E/AndroidRuntime(1220): FATAL EXCEPTION: main
05-30 05:55:52.489: E/AndroidRuntime(1220): java.lang.NullPointerException
05-30 05:55:52.489: E/AndroidRuntime(1220): at libcore.net.UriCodec.encode(UriCodec.java:132)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.net.URLEncoder.encode(URLEncoder.java:50)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Util.encodeUrl(Util.java:85)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Util.openUrl(Util.java:145)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Facebook.request(Facebook.java:717)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Facebook.request(Facebook.java:633)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.example.dragview.DragActivity.postImageonWall(DragActivity.java:458)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.example.dragview.DragActivity.onOptionsItemSelected(DragActivity.java:428)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:372)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(ActionBarActivity.java:244)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(ActionBarActivityDelegateICS.java:165)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:130)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(ActionBarActivityDelegateICS.java:300)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.view.View.performClick(View.java:4204)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.view.View$PerformClick.run(View.java:17355)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Handler.handleCallback(Handler.java:725)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Looper.loop(Looper.java:137)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 05:55:52.489: E/AndroidRuntime(1220): at dalvik.system.NativeStart.main(Native Method)