title: App crashes when image from gallery gets selected
body: <p>The camera function in my app really driving me in nuts !!!</p>
  
  <p>I have built an camera function in my app, but it crashed when I try to select the image from gallery.</p>
  
  <pre><code>Bitmap photo;
  private static final int RESULT_LOAD_IMAGE = 1;
  private static final int REQUEST_IMAGE_CAPTURE = 2;
  ImageView imageView;
  
    private void activeTakePhoto() {  // if select open camera 
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
      }
  
      private void activeGallery() { // if select choose from gallery
          Intent intent = new Intent(Intent.ACTION_PICK,
                  android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
          startActivityForResult(intent, RESULT_LOAD_IMAGE);
      }
  
   @Override
      protected void onActivityResult(int requestCode, int resultCode,
                                      Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          switch (requestCode) {
              case RESULT_LOAD_IMAGE:
                  if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp; null != data) {
                      Uri selectedImage = data.getData();
                      String[] filePathColumn = {MediaStore.Images.Media.DATA};
                      Cursor cursor = getContentResolver()
                              .query(selectedImage, filePathColumn, null, null,
                                      null);
                      cursor.moveToFirst();
                      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                      String picturePath = cursor.getString(columnIndex);
                      cursor.close();
                      Bitmap a = (BitmapFactory.decodeFile(picturePath));
                      photo = scaleBitmap(a, 200, 200);
                      imageView.setImageBitmap(photo);
                      //photo = decodeSampledBitmapFromUri(picturePath, 100, 20);
                      imageView.setImageBitmap(photo);
                  }
  
              case REQUEST_IMAGE_CAPTURE:
                  Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                  thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
  
                  //to generate random file name
                  String fileName = "tempimg.jpg";
  
                  try {
                      photo = (Bitmap) data.getExtras().get("data");
                      //captured image set in imageview
                      imageView.setImageBitmap(photo);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
          }
      }
  </code></pre>
  
  <p>If I remove the <code>activeTakePhoto()</code> and all the line after <code>case REQUEST_IMAGE_CAPTURE:</code>, the selected image can be displayed on <code>imageView</code>. </p>
  
  <p>If I remove <code>activeGallery()</code>, the captured image can be display on <code>imageView</code>.</p>
  
  <p><strong>But</strong>, if I use the snippet code I posted here (both function), it crashed when I select an image from gallery with the <code>logCat</code> error</p>
  
  <pre><code> 12-10 14:49:03.507      927-927/? E/HwSystemManager﹕ :ACTION_BATTERY_CHANGED pluged =2
      12-10 14:49:07.020  19428-19428/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
          java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/832821 flg=0x1 }} to activity {com.example.project.myapplication/com.example.project.myapplication.GUI.AddMoreClaims}: java.lang.NullPointerException
                  at android.app.ActivityThread.deliverResults(ActivityThread.java:3579)
              at android.app.ActivityThread.handleSendResult(ActivityThread.java:3622)
              at android.app.ActivityThread.access$1100(ActivityThread.java:169)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436)
  </code></pre>
  
  <p>and the line is   <code>Bitmap thumbnail = (Bitmap) data.getExtras().get("data");</code>. However, when I select capture image, the captured image still can display on <code>imageView</code>.</p>