com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1467)上的NullPointerException
我想从我的活动中捕获视频 这是我的源代码com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1467)上的NullPointerException,android,camera,Android,Camera,我想从我的活动中捕获视频 这是我的源代码 mTempVideoPath = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "Android/data/" + this.getPackageName() + "/files/" + System.currentTimeMillis() + ".mp4"; File videoFile = new File(mTempVideoPath);
mTempVideoPath = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "Android/data/" + this.getPackageName() + "/files/" + System.currentTimeMillis() + ".mp4";
File videoFile = new File(mTempVideoPath);
try {
if(videoFile.exists() == false) {
videoFile.getParentFile().mkdirs();
videoFile.createNewFile();
}
} catch (IOException e) {
Log.e(getCallingPackage(), "Could not create file.", e);
}
mCurrentVideoURI = Uri.fromFile(videoFile);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, mCurrentVideoURI);
// preventing it from listing items that aren't on the SD card
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_VIDEO);
但我得到了这个错误:
09-17 18:25:28.945: E/AndroidRuntime(30253): FATAL EXCEPTION: main
09-17 18:25:28.945: E/AndroidRuntime(30253): java.lang.NullPointerException
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.io.File.fixSlashes(File.java:185)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.io.File.<init>(File.java:134)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1467)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:965)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeStateRecording.handleRequest(CeStateRecording.java:69)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue.startFirstRequest(CeRequestQueue.java:123)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue.access$200(CeRequestQueue.java:32)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.sec.android.app.camera.CeRequestQueue$MainHandler.handleMessage(CeRequestQueue.java:60)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.os.Looper.loop(Looper.java:137)
09-17 18:25:28.945: E/AndroidRuntime(30253): at android.app.ActivityThread.main(ActivityThread.java:4507)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 18:25:28.945: E/AndroidRuntime(30253): at java.lang.reflect.Method.invoke(Method.java:511)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
09-17 18:25:28.945: E/AndroidRuntime(30253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
09-17 18:25:28.945: E/AndroidRuntime(30253): at dalvik.system.NativeStart.main(Native Method)
09-17 18:25:28.945:E/AndroidRuntime(30253):致命异常:main
09-17 18:25:28.945:E/AndroidRuntime(30253):java.lang.NullPointerException
09-17 18:25:28.945:E/AndroidRuntime(30253):位于java.io.File.fixSlashes(File.java:185)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于java.io.File.(File.java:134)
09-17 18:25:28.945:E/AndroidRuntime(30253):在com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1467)
09-17 18:25:28.945:E/AndroidRuntime(30253):在com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:965)
09-17 18:25:28.945:E/AndroidRuntime(30253):在com.sec.android.app.camera.cestatecording.handleRequest(cestatecording.java:69)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于com.sec.android.app.camera.CeRequestQueue.startFirstRequest(CeRequestQueue.java:123)
09-17 18:25:28.945:E/AndroidRuntime(30253):在com.sec.android.app.camera.CeRequestQueue.access$200(CeRequestQueue.java:32)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于com.sec.android.app.camera.CeRequestQueue$MainHandler.handleMessage(CeRequestQueue.java:60)
09-17 18:25:28.945:E/AndroidRuntime(30253):在android.os.Handler.dispatchMessage(Handler.java:99)上
09-17 18:25:28.945:E/AndroidRuntime(30253):在android.os.Looper.loop(Looper.java:137)上
09-17 18:25:28.945:E/AndroidRuntime(30253):位于android.app.ActivityThread.main(ActivityThread.java:4507)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于java.lang.reflect.Method.Invokenactive(本机方法)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于java.lang.reflect.Method.invoke(Method.java:511)
09-17 18:25:28.945:E/AndroidRuntime(30253):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
09-17 18:25:28.945:E/AndroidRuntime(30253):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
09-17 18:25:28.945:E/AndroidRuntime(30253):在dalvik.system.NativeStart.main(本机方法)
我在Galaxy S2上运行,ICS
请帮帮我
谢谢你我在这里找到了很好的解决方案:
MediaStore.EXTRA_输出不能正常工作并且存在问题。早期版本的Android(如2.3)存在导致媒体播放器崩溃的错误 拍完电影之后。重命名文件时引发NullPointer异常。 解决方法是在启动记录器时不提供文件Uri,并选择默认文件。我不确定这个bug是什么时候修复的,但是使用重命名的黑客在最近的版本中效果很好 感谢所有帮助,以下是我所做的:
private static final int VIDEO_REQUEST = 43; // some action code
File videoFile = new File(dirName, fileName);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
startActivityForResult(intent, VIDEO_REQUEST);
// Then later...
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
if (requestCode == VIDEO_REQUEST &&
Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
try { // cloodge
// first get filename used by media recorder
String[] projection = { MediaStore.Images.Media.DATA }; // columns
Cursor cursor = managedQuery(intent.getData(), projection, null, null, null);
int iColumn= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String tempFileName = cursor.getString(iColumn);
File tempFile = new File(tempFileName);
File videoFile = new File(dirName, fileName);
if (!tempFile.renameTo(videoFile)) { // try to rename it
// rename did not work. Copy and delete
FileInputStream in = new FileInputStream(tempFile);
FileOutputStream out = new FileOutputStream(videoFile);
byte[] buffer = new byte[1024]; // copy file to where we want it
int length;
while ((length = in.read(buffer)) > 0)
out.write(buffer, 0, length);
in.close();
out.close();
// now try to delete file created by the media recorder
tempFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
} // end of painful cloodge
// video file is in videoFile, like it should be
...
}
}
private static final int VIDEO_REQUEST=43;//一些动作代码
文件videoFile=新文件(目录名、文件名);
意向意向=新意向(MediaStore.ACTION\u VIDEO\u CAPTURE);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.HONEYCOMB)
intent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(videoFile));
startActivityForResult(意图、视频请求);
//后来。。。
ActivityResult上受保护的void(int-requestCode、int-resultCode、Intent-Intent){
super.onActivityResult(请求代码、结果代码、意图);
if(resultCode==RESULT\u OK){
if(requestCode==视频请求&&
Build.VERSION.SDK_INT0)
out.write(缓冲区,0,长度);
in.close();
out.close();
//现在尝试删除由媒体录制器创建的文件
tempFile.delete();
}
}捕获(例外e){
e、 printStackTrace();
}
}//痛楚结束
//视频文件是在视频文件中,就像它应该是一样
...
}
}
请显示异常的完整日志,包括默认摄像头的“原因”行原因,这些都是完整的日志