我的代码..
ImageView userpicture;
userpicture=(ImageView)findViewById(R.id.userImage);
URL img_value = null;
try {
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap mIcon1 = null;
try {
mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
userpicture.setImageBitmap(mIcon1);
并且记录了cat cat错误.......
05-12 15:42:11.728: E/AndroidRuntime(21176): FATAL EXCEPTION: main
05-12 15:42:11.728: E/AndroidRuntime(21176): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.avion.ryb/com.avion.ryb.slidingmenu.FaceBookLogin}: android.os.NetworkOnMainThreadException
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread.access$600(ActivityThread.java:145)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.os.Looper.loop(Looper.java:137)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread.main(ActivityThread.java:5099)
05-12 15:42:11.728: E/AndroidRuntime(21176): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 15:42:11.728: E/AndroidRuntime(21176): at java.lang.reflect.Method.invoke(Method.java:511)
05-12 15:42:11.728: E/AndroidRuntime(21176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)
05-12 15:42:11.728: E/AndroidRuntime(21176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)
05-12 15:42:11.728: E/AndroidRuntime(21176): at dalvik.system.NativeStart.main(Native Method)
05-12 15:42:11.728: E/AndroidRuntime(21176): Caused by: android.os.NetworkOnMainThreadException
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
05-12 15:42:11.728: E/AndroidRuntime(21176): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-12 15:42:11.728: E/AndroidRuntime(21176): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-12 15:42:11.728: E/AndroidRuntime(21176): at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
05-12 15:42:11.728: E/AndroidRuntime(21176): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
05-12 15:42:11.728: E/AndroidRuntime(21176): at com.avion.ryb.slidingmenu.FaceBookLogin.onCreate(FaceBookLogin.java:71)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.Activity.performCreate(Activity.java:5117)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
05-12 15:42:11.728: E/AndroidRuntime(21176): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
05-12 15:42:11.728: E/AndroidRuntime(21176): ... 11 more
答案 0 :(得分:0)
确保您的应用程序能够以正确的方式处理重定向。请参阅How to download image from facebook Graph API上的答案和https://developers.facebook.com/docs/graph-api/reference/v2.0/user/picture
上的Facebook文档