Note that there are some explanatory texts on larger screens.

plurals
  1. POMysterious NullpointerException after the built-in camera app saves my video properly
    text
    copied!<p>I have an activity that allows you to record a video if you open a dialog and click on an icon. The problem is that after I stop recording it throws a NullPointerException even though the video is saved properly. According to Log Cat the error is not in my code so I tried to place "checkpoints" in my code and I found out that even the onActivityResult of my activity is executed properly so now I'm out of idea what to do.</p> <p>Here is the Log Cat: </p> <p><img src="https://i.stack.imgur.com/VOsq6.png" alt="enter image description here"></p> <p>Code:</p> <p>these are from my dialog that invokes the camera app</p> <pre><code>Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high // start the Video Capture Intent ((Activity)context).startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); private static Uri getOutputMediaFileUri(int type) { return Uri.fromFile(getOutputMediaFile(type)); } private static File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStorageDirectory()+"/Movies", "MyCameraApp"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE){ mediaFile = new File(mediaStorageDir.getPath() + "/" + "IMG_"+ timeStamp + ".jpg"); } else if(type == MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + "/" + "VID_"+ timeStamp + ".mp4"); } else { return null; } return mediaFile; } </code></pre> <p>This code was more or less copied from the android developers site. As I mentioned even the onActivityResult of my activity is executed properly(where I dismiss the dialog) after this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload