title: Can't get image from camera with intent chooser on 4.2.2 AVD
body: <p>I'm working on a part of my application that allows a user to select an image either from camera or from  gallery, using an Intent chooser.</p>
  
  <p>It's working fine on my 2.2.1 android phone, but when i compile it on a 4.2.2 AVD it returns a null pointer error when i use the camera,</p>
  
  <pre><code> public void onClick(View View) 
  {
      Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT,null);
      galleryIntent.setType("image/*");
      galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
      galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
  
  
      Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
  
      Intent chooser = new Intent(Intent.ACTION_CHOOSER);
      chooser.putExtra(Intent.EXTRA_INTENT, galleryIntent);      
      chooser.putExtra(Intent.EXTRA_TITLE, "Chooser");
  
      Intent[] intentArray =  {cameraIntent}; 
      chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
      startActivityForResult(chooser,REQUEST_CODE);
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
      if (requestCode == REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK)
      {
      try 
              {
              if (bitmap != null) 
                  {
                      bitmap.recycle();
                  }
  
              InputStream stream = getContentResolver().openInputStream(data.getData());
              bitmap = BitmapFactory.decodeStream(stream);
              stream.close();
              imageView.setImageBitmap(bitmap);
              }
  
          catch (FileNotFoundException e) 
              {
                  e.printStackTrace();
              }
  
          catch (IOException e) 
              {
                  e.printStackTrace();
              }
      super.onActivityResult(requestCode, resultCode, data);
      }
  }
  </code></pre>
  
  <p>this is the error i get:<br>
  05-05 05:03:31.730: E/AndroidRuntime(820): Caused by: java.lang.NullPointerException</p>
  
  <p>And it said that the problem is in this line :</p>
  
  <pre><code>InputStream stream = getContentResolver().openInputStream(data.getData());
  </code></pre>
  
  <p>What am i doing wrong?</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>Now it's working and here is the solution:</p>
  
  <pre><code>    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
      if (requestCode == REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK)
      {
          if(data.getData()!=null)
          {
              try 
              {
              if (bitmap != null) 
                  {
                      bitmap.recycle();
                  }
  
              InputStream stream = getContentResolver().openInputStream(data.getData());
              bitmap = BitmapFactory.decodeStream(stream);
              stream.close();
              imageView.setImageBitmap(bitmap);
              }
  
          catch (FileNotFoundException e) 
              {
                  e.printStackTrace();
              }
  
          catch (IOException e) 
              {
                  e.printStackTrace();
              }
          } 
  
          else 
          {
              bitmap=(Bitmap) data.getExtras().get("data"); 
              imageView.setImageBitmap(bitmap);
          }
  
          super.onActivityResult(requestCode, resultCode, data);
      }
  }
  </code></pre>
  
  <p><strong>Thank you for you help!</strong></p>