title: camera captured image intent to other activity?
body: <p>Its very common question seen on StackOverflow and I have tried almost every solution on SO. I still get a <code>NullPointerExeption</code> in <code>onAtivityResult- data</code>.</p>
  
  <p>I have tried:</p>
  
  <ul>
  <li><p><a href="http://developer.android.com/training/camera/photobasics.html" rel="nofollow noreferrer">http://developer.android.com/training/camera/photobasics.html</a></p></li>
  <li><p><a href="http://developer.android.com/guide/topics/media/camera.html" rel="nofollow noreferrer">http://developer.android.com/guide/topics/media/camera.html</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity">Capture Image from Camera and Display in Activity</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/22325721/how-to-pass-captured-gallery-image-to-next-activity-in-android">how to pass captured/gallery image to next activity in android</a></p></li>
  <li><p><a href="http://hmkcode.com/android-camera-taking-photos-camera/" rel="nofollow noreferrer">http://hmkcode.com/android-camera-taking-photos-camera/</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/14558240/onactivityresult-returned-from-a-camera-intent-null">onActivityResult returned from a camera, Intent null</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/12564112/android-camera-onactivityresult-intent-is-null-if-it-had-extras">android camera: onActivityResult() intent is null if it had extras</a></p></li>
  </ul>
  
  <p>The last code which I have tried for fourth time is given below:</p>
  
  <p><strong>On Button Click:</strong></p>
  
  <pre><code>Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  File file=getOutputMediaFile(1);
                  picUri = Uri.fromFile(file); // create
                  cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri); // set the image file
                      startActivityForResult(cameraIntent, REQUEST_TAKE_PHOTO);
  </code></pre>
  
  <p><strong>getOutputMediaFile()</strong></p>
  
  <pre><code> private  File getOutputMediaFile(int type) {
          File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                  Environment.DIRECTORY_PICTURES), "MyApplication");
  
          /**Create the storage directory if it does not exist*/
          if (!mediaStorageDir.exists()) {
              if (!mediaStorageDir.mkdirs()) {
                  return null;
              }
  
          }
          String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
          File mediaFile;
          if (type == 1){
              mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                      "IMG_"+ timeStamp + ".png");
          } else {
              return null;
          }
  
          return mediaFile;
      }
  </code></pre>
  
  <p><strong>onActivityResult()</strong></p>
  
  <pre><code> protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
          super.onActivityResult(requestCode, resultCode, intent);
          if (resultCode == RESULT_OK &amp;&amp; requestCode == REQUEST_TAKE_PHOTO &amp;&amp; intent != null){
  
  
              Uri selectedImage = intent.getData();
              String[] filePathColumn = {MediaStore.Images.Media.DATA};
  
              Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              //file path of captured image
              imagepath = cursor.getString(columnIndex);
              //file path of captured image
              File f = new File(imagepath);
              String filename = f.getName();
              cursor.close();
              Bitmap imageData = BitmapFactory.decodeFile(filename);
  //            Bitmap imageData = (Bitmap) data.getExtras().get("data");
  
              Intent i = new Intent(this, EditImageActivity.class);
              i.putExtra("path", imageData );
              startActivity(i);
          }
      }
  }
  </code></pre>
  
  <p>Please suggest something better which is not mentioned in above links which I already have referred because that didn't work for me.</p>
  
  <p>I am using Android Atudio, with <em>api 10+</em>.</p>
  
  <p>Crash log:</p>
  
  <pre><code>10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime: FATAL EXCEPTION: main
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime: Process: com.example.dell.drawdemo, PID: 25060
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.example.dell.drawdemo/com.example.dell.drawdemo.MainActivity}: java.lang.NullPointerException
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.deliverResults(ActivityThread.java:3593)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3636)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.access$1300(ActivityThread.java:151)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:110)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5334)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:  Caused by: java.lang.NullPointerException
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at com.example.dell.drawdemo.MainActivity.onActivityResult(MainActivity.java:131)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.Activity.dispatchActivityResult(Activity.java:5546)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.deliverResults(ActivityThread.java:3589)
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3636) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.access$1300(ActivityThread.java:151) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:110) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5334) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676) 
  10-12 17:48:49.934 25060-25060/com.example.dell.drawdemo E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>