title: Application crash after taking a photo
body: <p>I am using this code to create a simple camera apps. I can take a photo. However, the application crash after taking the photo.      </p>
  
  <pre><code>{
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);                       
  
      File imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "abc.jpg");
  
  
      Uri store= Uri.fromFile(imageFile);
      intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, store);
      intent.putExtra(android.provider.MediaStore.EXTRA_VIDEO_QUALITY, 0);
      startActivityForResult(intent, 0);
  }
  </code></pre>
  
  <p>/***************************************onActivityResult***************************************/</p>
  
  <pre><code>    @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == 0) {
              switch (resultCode) {
                  case Activity.RESULT_OK:
                      if (imageFile.exists())
                      {
                          Toast.makeText(this, "The file was saved at " + imageFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                      }
                      else
                      {
                          Toast.makeText(this, "Error saving the file ", Toast.LENGTH_LONG).show();
                      }
                          break;
                  case Activity.RESULT_CANCELED:
                              break;
                          default:
                              break;
                      }
              }
          }
  </code></pre>
  
  <p>Below is the logcat.</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {com.camera/com.camera.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference</p>
    
    <p>at android.app.ActivityThread.deliverResults(ActivityThread.java:3758)</p>
    
    <p>at android.app.ActivityThread.handleSendResult(ActivityThread.java:3801)</p>
    
    <p>at android.app.ActivityThread.access$1400(ActivityThread.java:157)</p>
    
    <p>at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
                         at android.os.Handler.dispatchMessage(Handler.java:102)
                         at android.os.Looper.loop(Looper.java:148)</p>
    
    <p>at android.app.ActivityThread.main(ActivityThread.java:5551)
                         at java.lang.reflect.Method.invoke(Native Method)</p>
    
    <p>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)</p>
    
    <p>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)</p>
    
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference</p>
    
    <p>at com.camera.MainActivity.onActivityResult(MainActivity.java:43)</p>
    
    <p>at android.app.Activity.dispatchActivityResult(Activity.java:6463)</p>
    
    <p>at android.app.ActivityThread.deliverResults(ActivityThread.java:3754)</p>
    
    <p>at android.app.ActivityThread.handleSendResult(ActivityThread.java:3801) </p>
    
    <p>at android.app.ActivityThread.access$1400(ActivityThread.java:157) </p>
    
    <p>at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) </p>
    
    <p>at android.os.Handler.dispatchMessage(Handler.java:102)
     
                         at android.os.Looper.loop(Looper.java:148) </p>
    
    <p>at android.app.ActivityThread.main(ActivityThread.java:5551) 
                         at java.lang.reflect.Method.invoke(Native Method) </p>
    
    <p>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) </p>
    
    <p>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) </p>
  </blockquote>
  
  <p>I can't figure out why is this happening. Does anyone know how should I fixed the error? Thanks!</p>