获得从摄像头捕获视频空指针异常,Android的? [英] Getting nullpointer exception on capturing VIDEO from camera, android?
本文介绍了获得从摄像头捕获视频空指针异常,Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我测试了索尼,三星以及它工作正常HTC设备我的code。但它不像karbonn等其他设备的工作......
I tested my code on sony, samsung and HTC devices where it works fine. But it doesnt work on other devices like karbonn etc...
下面是我的code
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create
intent.putExtra(MediaStore.EXTRA_OUTPUT,fileUri); // set the video file name
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
这是onactivity结果code
This is the onactivity result code
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Video captured and saved to fileUri specified in the Intent
Uri videoUri = fileUri;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(videoUri, proj,
null, null, null);
if (cursor.moveToFirst()) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
filePath = cursor.getString(column_index);
}
cursor.close();
Log.d("LOGCAT", "Video path is: " + filePath);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath,
MediaStore.Images.Thumbnails.MINI_KIND);
Toast.makeText(this, "Video saved to:\n" + filePath,
Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the video capture
} else {
// Video capture failed, advise user
}
}
这是例外的,我得到的logcat
This is the logcat of exception I am getting
FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=Intent { dat=file:///mnt/sdcard/ext_sdcard/Pictures/Crime/VID_20131205_121435.mp4 }} to activity {com.pstpl.crime/com.pstpl.crimeverify.CrimeReportActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
at android.app.ActivityThread.access$1100(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
at android.os.Handler.dispatchMessage(Handler.java:99)
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)
Caused by: java.lang.NullPointerException
at com.pstpl.crimeverify.CrimeReportActivity.onActivityResult(CrimeReportActivity.java:359)
at android.app.Activity.dispatchActivityResult(Activity.java:4662)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
行中没有359 ----->如果(cursor.moveToFirst()){
Line no 359 is -----> if (cursor.moveToFirst()) {
推荐答案
试试这个..
修改以下行
Cursor cursor = getContentResolver().query(fileUri, proj,
null, null, null);
为
Cursor cursor = getContentResolver().query(videoUri, proj,
null, null, null);
由于您的URI路径指定为这样的乌里VIDEOURI = fileURI所;
那么你的游标中加入了fileURI
because your Uri path assigned as like this Uri videoUri = fileUri;
then your added in cursor as fileUri
编辑:
try {
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(videoUri, proj,
null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(proj[0]);
filePath = cursor.getString(columnIndex);
} catch (Exception e) {
filePath = videoUri.getPath();
}
Log.v("log", "filePath is : " + filePath);
这篇关于获得从摄像头捕获视频空指针异常,Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文