title: Download profile image from facebook
body: <p>i am trying to download the facebook image profile with AsyncTask, however i get that the bitmap that downloaded is null and therefore i get a nullPointerExceprion.</p>
  
  <p>this is my code:</p>
  
  <pre><code>private synchronized void downloadAvatar(final String user_id,final ImageView iv) {
          AsyncTask&lt;Void, Void, Bitmap&gt; task = new AsyncTask&lt;Void, Void, Bitmap&gt;() {
  
              @Override
              public Bitmap doInBackground(Void... params) {
                  URL fbAvatarUrl = null;
                  Bitmap fbAvatarBitmap = null;
                  try {
                      fbAvatarUrl = new URL("http://graph.facebook.com/"+user_id+"/picture");
                      fbAvatarBitmap = BitmapFactory.decodeStream(fbAvatarUrl.openConnection().getInputStream());
                  } catch (MalformedURLException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  return fbAvatarBitmap;
              }
  
              @Override
              protected void onPostExecute(Bitmap result) {
  
  
                  iv.setImageBitmap(result);
              }
  
          };
          task.execute();
      }
  </code></pre>
  
  <p>(user_id) is a exist profile id -i checked it in the debug mode..</p>
  
  <p>i get a nullPointerException at this line:</p>
  
  <pre><code>iv.setImageBitmap(result);
  </code></pre>
  
  <p>(result is null)</p>
  
  <p>also, here is the logcat:</p>
  
  <pre><code>04-12 14:16:40.140: E/AndroidRuntime(19304): FATAL EXCEPTION: main
  04-12 14:16:40.140: E/AndroidRuntime(19304): java.lang.NullPointerException
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at com.example.sal.ProfileActivity$15.onPostExecute(ProfileActivity.java:1998)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at com.example.sal.ProfileActivity$15.onPostExecute(ProfileActivity.java:1)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.os.AsyncTask.finish(AsyncTask.java:602)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.os.Looper.loop(Looper.java:137)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at android.app.ActivityThread.main(ActivityThread.java:4575)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
  04-12 14:16:40.140: E/AndroidRuntime(19304):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>