1
votes

Error:

FATAL EXCEPTION: main
java.lang.NullPointerException at java.io.File.fixSlashes(File.java:185)
at java.io.File.(File.java:134) at ua.romanpotapskiy.antihawk.prokaton.DeliverActivity.galleryAddPic(DeliverActivity.java:308) at ua.romanpotapskiy.antihawk.prokaton.DeliverActivity.onClick(DeliverActivity.java:246) at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

Code:

private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent("android.media.action.IMAGE_CAPTURE");
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                Toast.makeText(this, "Error!", Toast.LENGTH_SHORT).show();
            }
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, 0);
            }
        }
    }

private File createImageFile() throws IOException {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/Prokaton/Big");
        File image = File.createTempFile(imageFileName, ".jpg", storageDir);

        mCurrentPhotoPath = image.getAbsolutePath();
        imageName = image.getName();
        ...
        return image;
    }

private void galleryAddPic() {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(mCurrentPhotoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}

Error on this line: File f = new File(mCurrentPhotoPath);

Error on Android 4.0.3. In the other version works fine.

2
there is some problem with slashes in your file pathVivek Mishra
The error clearly indicates that mCurrentPhotoPath is null so you need to assign a non-null value to it prior to your call to galleryAddPic() method.Saheed

2 Answers

1
votes

Based on the code you posted, my guess is that you experienced the error prior to dispatchTakePictureIntent() getting called since it is this method that calls the createImageFile() method which sets the mCurrentPhotoPath variable with a non-null value.

A simple fix would be to update the galleryAddPic() method with a not null check like so:

    private void galleryAddPic() {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        if (mCurrentPhotoPath == null) {
            return;
        }
        File f = new File(mCurrentPhotoPath);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);
    }
0
votes

mCurrentPhotoPath is null in your code so provide full code to check this error.enter image description here

image.getabsolutePath(); is null in your code.