title: facebook profile image fetching error
body: <p>This is my MainLogin.java activity coding for facebook login</p>
  
  <pre><code>public class MainLogin extends Activity implements OnClickListener{
  
      Button login;
      ImageView pic;
      Facebook fb;
      TextView welcome;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.main_login);
  
          String APP_ID = getString(R.string.APP_ID);
          fb = new Facebook(APP_ID);
          login = (Button) findViewById(R.id.facebook_login);
          pic = (ImageView) findViewById(R.id.user_pic);
          welcome = (TextView) findViewById(R.id.welcome);
          updateLoginState();
  
      }
  
      public void updateLoginState() {
          if(fb.isSessionValid()){
              Toast.makeText(this, "Logged In successflly2", Toast.LENGTH_SHORT).show();
              pic.setVisibility(ImageView.VISIBLE);
  
              JSONObject obj = null;
              URL img_url = null;
  
              try {
                  String jsonUser = fb.request("me");
                  obj = Util.parseJson(jsonUser);
  
                  String id = obj.optString("id");
                  String name = obj.optString("name");
  
                  welcome.setText("Welcome"+name);
  
                  img_url = new URL("http://graph.facebook.com/"+id+"/picture?type=small");
                  Bitmap bmp = BitmapFactory.decodeStream(img_url.openConnection().getInputStream());
                  pic.setImageBitmap(bmp);
              } catch (FacebookError e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (MalformedURLException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          }else{
              pic.setVisibility(ImageView.INVISIBLE);
          }
      }
  
      public void onClick(View v) {
          switch(v.getId()){
          case R.id.facebook_login:
              if(fb.isSessionValid()){
                  try {
                      fb.logout(getApplicationContext());
                      updateLoginState();
                  } catch (MalformedURLException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }else{
                  fb.authorize(MainLogin.this, new DialogListener() {
                      @Override
                      public void onFacebookError(FacebookError e) {
                      }
                      @Override
                      public void onError(DialogError e) {
                          Toast.makeText(getApplicationContext(), "error",
                                  Toast.LENGTH_SHORT).show();
  
                      }
                      @Override
                      public void onComplete(Bundle values) {
                          updateLoginState();
                          Toast.makeText(getApplicationContext(), "Logged in Successfully!",
                                  Toast.LENGTH_SHORT).show();
                      }
                      @Override
                      public void onCancel() {
                          Toast.makeText(getApplicationContext(), "Canceld",
                                  Toast.LENGTH_SHORT).show();
                      }
                  });
              }
              break;
          }
      }
  }
  </code></pre>
  
  <p>This app login successfully but in the <code>updateLoginState()</code> following error occurs . this is my logcat</p>
  
  <pre><code>    08-15 15:26:43.474: E/AndroidRuntime(16241): android.os.NetworkOnMainThreadException
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1125)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:70)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Util.openUrl(Util.java:219)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Facebook.requestImpl(Facebook.java:806)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Facebook.request(Facebook.java:732)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at in.blogspot.pcnlap.sha_main_stream.MainLogin.updateLoginState(MainLogin.java:77)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at in.blogspot.pcnlap.sha_main_stream.MainLogin.access$1(MainLogin.java:68)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at in.blogspot.pcnlap.sha_main_stream.MainLogin$1.onComplete(MainLogin.java:145)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Facebook.onSessionCallback(Facebook.java:345)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Facebook.access$11(Facebook.java:326)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.android.Facebook$1.call(Facebook.java:304)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.facebook.Session$3$1.run(Session.java:1190)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at android.os.Handler.handleCallback(Handler.java:615)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at android.os.Handler.dispatchMessage(Handler.java:92)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at android.os.Looper.loop(Looper.java:153)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at android.app.ActivityThread.main(ActivityThread.java:5086)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at java.lang.reflect.Method.invoke(Method.java:511)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
  08-15 15:26:43.474: E/AndroidRuntime(16241):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>When I'm tries to fetch the profile image of the user use <code>updateLoginState()</code> the application itself crashes other than this application successfully logs into the facebook, Here i've been using the deprecated methods only. if any good and simple tutorial available for facebook login and something more then suggest me</p>