Android 拍照很简单。onActivityResult空指针

Android 拍照很简单。onActivityResult空指针,android,nullpointerexception,Android,Nullpointerexception,我在这里寻找帮助,但似乎没有什么是完全相关的,或帮助我修复我所面临的错误。我把所有的东西都抄袭了 如何从此行中删除空指针 Bundle extras = data.getExtras(); 代码的其余部分在这里 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE_CAPTURE &a

我在这里寻找帮助,但似乎没有什么是完全相关的,或帮助我修复我所面临的错误。我把所有的东西都抄袭了

如何从此行中删除空指针

Bundle extras = data.getExtras();
代码的其余部分在这里

@Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == REQUEST_IMAGE_CAPTURE && 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;
}
堆栈跟踪

>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)