我使用以下代码将图像上传到我的 Facebook 墙。
try {
bitmap=BitmapFactory.decodeFile(imagePostion);
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(
"https://graph.facebook.com/me/photos?access_token="+ a);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("source", new ByteArrayBody(data, imagePostion));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,localContext);
Log.v("Response !!!!!!!!",response+"");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我在这一行得到空指针异常
ByteArrayOutputStream bos = new ByteArrayOutputStream();
需要帮忙。