title: Android Camera : when capturing image data intent returns null
body: <p>I'm using a button which will call the device camera.</p>
  
  <pre><code>private void captureImage() {
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
      fileUri = getOutputMediaFileUri(ImageUtils.MEDIA_TYPE_IMAGE);
  
      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
  
      // start the image capture Intent
      startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
  }
  
  public Uri getOutputMediaFileUri(int type) {
      item = ImageUtils.getOutputMediaFile(type, getActivity());
  
      return item.getIcon();
  }
  </code></pre>
  
  <p>and getOutputMediaFile() method is,</p>
  
  <pre><code>public static ImageItem getOutputMediaFile(int type, Activity activity) {
  
      // External sdcard location
      File mediaStorageDir = new File(
              Environment
                      .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
              IMAGE_DIRECTORY_NAME);
  
      // Create the storage directory if it does not exist
      if (!mediaStorageDir.exists()) {
          if (!mediaStorageDir.mkdirs()) {
              Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                      + IMAGE_DIRECTORY_NAME + " directory");
              return null;
          }
      }
  
      // Create a media file name
      Date date = new Date();
      String timeStamp = CommonUtils.dateToString(date, "yyyyMMddHHmmss");
      String dateString = CommonUtils.dateToString(date,
              "yyyy/MM/dd HH:mm:ss");
  
      File mediaFile;
      if (type == MEDIA_TYPE_IMAGE) {
          mediaFile = new File(mediaStorageDir.getPath() + File.separator
                  + "IMG_" + timeStamp + ".jpg");
      }
  
      else {
          return null;
      }
  
      ImageItem item = new ImageItem();
      item.setId(timeStamp);
      item.setmIcon(Uri.fromFile(mediaFile));
      item.setDate(dateString);
      item.setmSpans(1);
  
      // save image in on activity result
  
      return item;
  }
  </code></pre>
  
  <p>on the same activity I call the OnActivityResult method for the image result,</p>
  
  <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE
              &amp;&amp; resultCode == RESULT_OK) {
  
          String[] fileColumn = { MediaStore.Images.Media.DATA };
          Cursor cursor = getActivity().getContentResolver().query(fileUri,
                  fileColumn, null, null, null);
          String contentPath = null;
          if (cursor.moveToFirst()) {
              contentPath = cursor.getString(cursor
                      .getColumnIndex(fileColumn[0]));
  
              horseImage.setImageBitmap(ImageManager
                      .getImage(new ImageManagerRequest(contentPath)));
  
          } else if (resultCode == RESULT_CANCELED) {
              Toast.makeText(getActivity(), "Capture Cancelled",
                      Toast.LENGTH_LONG).show();
          } else {
              Toast.makeText(getActivity(), "Capture failed",
                      Toast.LENGTH_LONG).show();
          }
  
      }
  
  }
  </code></pre>
  
  <p>when run this code i got the following error log.</p>
  
  <pre><code>09-24 19:17:10.250: E/AndroidRuntime(16995): FATAL EXCEPTION: main
  09-24 19:17:10.250: E/AndroidRuntime(16995): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=198496, result=-1, data=null} to activity {com.eyepax.horseapp/com.eyepax.horseapp.ui.activities.MainActivity}: java.lang.NullPointerException
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3141)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread.access$1100(ActivityThread.java:130)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.os.Handler.dispatchMessage(Handler.java:99)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.os.Looper.loop(Looper.java:137)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread.main(ActivityThread.java:4745)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at java.lang.reflect.Method.invokeNative(Native Method)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at java.lang.reflect.Method.invoke(Method.java:511)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at dalvik.system.NativeStart.main(Native Method)
  09-24 19:17:10.250: E/AndroidRuntime(16995): Caused by: java.lang.NullPointerException
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at com.eyepax.horseapp.ui.activities.AddHorseBasicInfo.onActivityResult(AddHorseBasicInfo.java:270)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:167)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.Activity.dispatchActivityResult(Activity.java:5192)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
  09-24 19:17:10.250: E/AndroidRuntime(16995):    ... 11 more
  </code></pre>
  
  <p>fileUri is a global variable. i go through the many examples but i can't resolve my issue. many examples giving this happening because of the Intent data getting null.then i'm changed onActivityResult as follow but then it's escape.</p>
  
  <pre><code>if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE &amp;&amp; resultCode == RESULT_OK
              &amp;&amp; null != data) {}
  </code></pre>
  
  <p>help me to resolve this issue.</p>