Androidアプリにログインボタンがありました。ログインしているときは問題なく動作しますが、ログアウトしようとするとこのエラーが発生します。エラーの原因がわかりません。
11-12 14:44:12.358: E/AndroidRuntime(2334): FATAL EXCEPTION: main
11-12 14:44:12.358: E/AndroidRuntime(2334): android.os.NetworkOnMainThreadException
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-12 14:44:12.358: E/AndroidRuntime(2334): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
11-12 14:44:12.358: E/AndroidRuntime(2334): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-12 14:44:12.358: E/AndroidRuntime(2334): at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
11-12 14:44:12.358: E/AndroidRuntime(2334): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.facebook.android.Util.openUrl(Util.java:215)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.facebook.android.Facebook.request(Facebook.java:775)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.facebook.android.Facebook.request(Facebook.java:691)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.facebook.android.Facebook.logout(Facebook.java:650)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.example.facebook.MainActivity.onClick(MainActivity.java:57)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.view.View.performClick(View.java:4084)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.view.View$PerformClick.run(View.java:16966)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.os.Handler.handleCallback(Handler.java:615)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.os.Looper.loop(Looper.java:137)
11-12 14:44:12.358: E/AndroidRuntime(2334): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-12 14:44:12.358: E/AndroidRuntime(2334): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 14:44:12.358: E/AndroidRuntime(2334): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-12 14:44:12.358: E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 14:44:12.358: E/AndroidRuntime(2334): at dalvik.system.NativeStart.main(Native Method)
ここに私のログアウトコードがあります
private void updateButtonImage() {
// TODO Auto-generated method stub
if(fb.isSessionValid()){
button.setImageResource(R.drawable.logout_button);
}else{
button.setImageResource(R.drawable.login_button);
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(fb.isSessionValid()){
try {
fb.logout(getApplicationContext());
updateButtonImage();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
fb.authorize(MainActivity.this,new String[] {"email", "publish_stream"}, new DialogListener() {
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Facebook error", Toast.LENGTH_SHORT).show();
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
updateButtonImage();
}
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Cancel", Toast.LENGTH_SHORT).show();
}
});
}
}
誰でもエラーの原因を指摘できますか?
ありがとう。