title: Getting error for Login and Logout using facebook SDK
body: <p>this is my MainActivity:</p>
  
  <pre><code>package com.FBupdater;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ImageButton;
  import android.widget.Toast;
  
  import com.facebook.android.DialogError;
  import com.facebook.android.Facebook;
  import com.facebook.android.Facebook.DialogListener;
  import com.facebook.android.FacebookError;
  
  public class MainActivity extends Activity implements OnClickListener {
  
      String APP_ID = getString(R.string.APP_ID);
      Facebook fb;
      ImageButton button;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          fb = new Facebook(APP_ID);
  
          button = (ImageButton)findViewById(R.id.loginbtn);
          button.setOnClickListener(this);
  
          updateContentView();
      }
  
      private void updateContentView() {
          // TODO Auto-generated method stub
          if(fb.isSessionValid()){
              Toast.makeText(MainActivity.this, "done", Toast.LENGTH_LONG).show();
              button.setImageResource(R.drawable.logout);
          }else{
              button.setImageResource(R.drawable.login);
          }
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          if(fb.isSessionValid()){
              //button close our session - log out of facebook
              try {
                  fb.logout(getApplicationContext());
                  updateContentView();
              } catch (MalformedURLException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }else{
              //login to facebook
              fb.authorize(MainActivity.this, new DialogListener() {
  
                  @Override
                  public void onFacebookError(FacebookError e) {
                      // TODO Auto-generated method stub
                      Toast.makeText(MainActivity.this, "onFBerror", Toast.LENGTH_LONG).show();
                  }
  
                  @Override
                  public void onError(DialogError e) {
                      // TODO Auto-generated method stub
                      Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_LONG).show();
                  }
  
                  @Override
                  public void onComplete(Bundle values) {
                      // TODO Auto-generated method stub
                      updateContentView(); 
                  }
  
                  @Override
                  public void onCancel() {
                      // TODO Auto-generated method stub
                      Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_LONG).show();
  
                  }
              });
          }
      }
  
  }
  </code></pre>
  
  <p>this is my AndroidManifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.FBupdater"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.FBupdater.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>this is my activity_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:gravity="center"
      android:layout_gravity="center"
      android:background="#000000" &gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="70dp"
          android:layout_gravity="center"
          android:gravity="center"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/notloggedinmessage"
              android:textColor="#ffffff"
              android:textSize="20sp" /&gt;
  
          &lt;ImageButton
              android:id="@+id/loginbtn"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:contentDescription="@drawable/login"
              android:src="@drawable/login" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and this the error log:</p>
  
  <p>////after clicking the logout button:</p>
  
  <pre><code>11-28 15:22:56.824: D/AndroidRuntime(2123): Shutting down VM
  11-28 15:22:56.824: W/dalvikvm(2123): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
  11-28 15:22:57.034: E/AndroidRuntime(2123): FATAL EXCEPTION: main
  11-28 15:22:57.034: E/AndroidRuntime(2123): android.os.NetworkOnMainThreadException
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:71)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Util.openUrl(Util.java:215)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.request(Facebook.java:777)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.request(Facebook.java:693)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.logout(Facebook.java:652)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.timelystatusupdater.MainActivity.onClick(MainActivity.java:54)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.view.View.performClick(View.java:3511)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.view.View$PerformClick.run(View.java:14105)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Handler.handleCallback(Handler.java:605)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Handler.dispatchMessage(Handler.java:92)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Looper.loop(Looper.java:137)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.lang.reflect.Method.invokeNative(Native Method)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.lang.reflect.Method.invoke(Method.java:511)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  11-28 15:22:57.034: E/AndroidRuntime(2123):     at dalvik.system.NativeStart.main(Native Method)
  11-28 15:22:57.534: D/dalvikvm(2123): GC_CONCURRENT freed 400K, 9% free 5888K/6407K, paused 10ms+34ms
  11-28 15:22:57.874: I/dalvikvm(2123): threadid=3: reacting to signal 3
  11-28 15:22:57.994: I/dalvikvm(2123): Wrote stack traces to '/data/anr/traces.txt'
  11-28 15:23:07.315: I/Process(2123): Sending signal. PID: 2123 SIG: 9
  </code></pre>
  
  <p>In the video tutorial he said it is so simple. he used facebook.logout(Context context) function. His code worked fine but mine does not.</p>
  
  <p>So, what is the problem, I don't understand. Thanks in advance.</p>
  
  <p><strong>N.B:</strong> I am new in Android and the Facebook SDK. In fact, this is my first project in android.</p>
  
  <p>I run this project for min android sdk 8, target sdk 16
  and when I run it in android 2.3.3 (api 10) emulator I can logout very easily but when I run it in android 4.0.3 (api 15) emulator I can login but when I try to logout the app crashes and i get the error above.</p>
  
  <p>I am following a video tutorial: <a href="http://www.youtube.com/watch?v=SrJsLFAYITI&amp;feature=plcp" rel="nofollow noreferrer">mybringback all 11 videos about facebook sdk in android</a></p>
  
  <p>In the video tutorial he said it is so simple. He used <code>facebook.logout(Context context)</code> function. His code works fine but mine does not.</p>