title: Taking Photos Simply. onActivityResult null pointer
body: <p>I have looked through here for help but nothing seems to be completely related or helped me fix the error I am facing. I copied everything from <a href="https://developer.android.com/training/camera/photobasics.html#TaskScalePhoto" rel="nofollow noreferrer">https://developer.android.com/training/camera/photobasics.html#TaskScalePhoto</a></p>
  
  <p>How do I remove the null pointer from this line?</p>
  
  <pre><code>Bundle extras = data.getExtras();
  </code></pre>
  
  <p>The rest of the code is here.</p>
  
  <pre><code>@Override
       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
      if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
          Bundle extras = data.getExtras();
          Bitmap imageBitmap = (Bitmap) extras.get("data");
          mImageView.setImageBitmap(imageBitmap);
  
      }
      //galleryAddPic();
  }
  
  
  //Creates Intent
  private void dispatchTakePictureIntent() {
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      // Ensure that there's a camera activity to handle the intent
      if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
          // Create the File where the photo should go
          File photoFile = null;
          try {
              photoFile = createImageFile();
          } catch (IOException ex) {
              // Error occurred while creating the File
              return;
          }
          // Continue only if the File was successfully created
          if (photoFile != null) {
              Uri photoURI = FileProvider.getUriForFile(this,
                      "com.joseph.webber.dartapp.fileprovider",
                      photoFile);
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
              startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
          }
      }
  }
  
  
  
  
  //Creates File Path and Name
  private File createImageFile() throws IOException {
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
      String imageFileName = "JPEG_" + timeStamp + "_";
      File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
      File image = File.createTempFile(
              imageFileName,  /* prefix */
              ".jpg",         /* suffix */
              storageDir      /* directory */
      );
  
      // Save a file: path for use with ACTION_VIEW intents
      mCurrentPhotoPath = image.getAbsolutePath();
      return image;
  }
  </code></pre>
  
  <p>Stacktrace</p>
  
  <pre><code>&gt;06-04 01:28:39.945  20181-20181/com.joseph.webber.dartapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.joseph.webber.dartapp, PID: 20181
      java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.joseph.webber.dartapp/com.joseph.webber.dartapp.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
              at android.app.ActivityThread.deliverResults(ActivityThread.java:4925)
              at android.app.ActivityThread.handleSendResult(ActivityThread.java:4968)
              at android.app.ActivityThread.access$1600(ActivityThread.java:222)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:158)
              at android.app.ActivityThread.main(ActivityThread.java:7229)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
              at com.joseph.webber.dartapp.LoginActivity.onActivityResult(LoginActivity.java:98)
              at android.app.Activity.dispatchActivityResult(Activity.java:7137)
              at android.app.ActivityThread.deliverResults(ActivityThread.java:4921)
              at android.app.ActivityThread.handleSendResult(ActivityThread.java:4968)
              at android.app.ActivityThread.access$1600(ActivityThread.java:222)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:158)
              at android.app.ActivityThread.main(ActivityThread.java:7229)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  </code></pre>