Process: com.android.camera2, PID: 21756
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.android.camera.FocusOverlayManager.overrideFocusMode(com.android.ex.camera2.portability.CameraCapabilities$FocusMode)' on a null object reference
private void startVideo() {
Intent intent = new Intent();
//指定动作,启动相机
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
Log.d(TAG, "指定启动相机动作,完成。");
//创建文件
createVideoFile();
Log.d(TAG, "创建视频文件结束。");
//添加权限
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Log.d(TAG, "添加权限。");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//做一些处理
//获取uri
mVideoUri = FileProvider.getUriForFile(this, "com.example.camera.fileprovider", mVideoFile);
} else {
//在版本低于此的时候,做一些处理
mVideoUri = Uri.fromFile(mVideoFile);
}
Log.d(TAG, "根据视频文件路径获取uri。");
//将uri加入到额外数据
intent.putExtra(MediaStore.EXTRA_OUTPUT, mVideoUri);
Log.d(TAG, "将uri加入启动相机的额外数据。");
Log.d(TAG, "启动相机...");
//启动相机并要求返回结果
startActivityForResult(intent, VIDEO_RESULT_CODE);
Log.d(TAG, "拍摄中...");
}