Получение java.lang.RuntimeException: сбой при доставке результата ResultInfo из NPE, по-видимому, в результате вызова моей функции getRealPathFromURI.
Захват видео работает нормально, но захват изображения выбрасывает NPE. И изображение, и видео отлично работают на моем Evo.
03-30 09:34:25.725 D/ZoorniApp( 2509): Handling activity result. requestCode:12345 resultCode:-1
03-30 09:34:25.733 D/AndroidRuntime( 2509): Shutting down VM
03-30 09:34:25.733 W/dalvikvm( 2509): threadid=3: thread exiting with uncaught exception (group=0x4001e2e0)
03-30 09:34:25.733 E/AndroidRuntime( 2509): Uncaught handler: thread main exiting due to uncaught exception
03-30 09:34:25.741 E/AndroidRuntime( 2509): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.mobile.zoorni/com.mobile.zoorni.ZoorniMobile}: java.lang.NullPointerException
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.deliverResults(ActivityThread.java:3391)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3433)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.access$2900(ActivityThread.java:121)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.os.Looper.loop(Looper.java:136)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.main(ActivityThread.java:4425)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at java.lang.reflect.Method.invoke(Method.java:521)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at dalvik.system.NativeStart.main(Native Method)
03-30 09:34:25.741 E/AndroidRuntime( 2509): Caused by: java.lang.NullPointerException
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.content.ContentResolver.acquireProvider(ContentResolver.java:757)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.content.ContentResolver.query(ContentResolver.java:200)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.Activity.managedQuery(Activity.java:1495)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.mobile.zoorni.ZoorniMobile.getRealPathFromURI(ZoorniMobile.java:287)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.mobile.zoorni.ZoorniMobile.onActivityResult(ZoorniMobile.java:251)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.Activity.dispatchActivityResult(Activity.java:3828)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.deliverResults(ActivityThread.java:3387)
Вот соответствующая функция:
public String getRealPathFromURI(Uri contentUri) {
String column;
column = "";
if (fileType == "picture") {
column = MediaStore.Images.Media.DATA;
}
if (fileType == "video") {
column = MediaStore.Video.Media.DATA;
}
String[] proj = { column };
Cursor cursor = managedQuery(contentUri, proj, null, null, null); // here lies the exception!
int column_index = cursor.getColumnIndex( column );
if (column_index == -1) {
alert("Path missing", "Could not locate the file requested", this);
return "";
}
cursor.moveToFirst();
return cursor.getString(column_index);
}
Вот соответствующий санированный код (только что удаленный клиент)
/*
* Call the camera activity for video or picture
*/
protected void startCaptureIntent(String actionCode, int requestCode, int media) {
Intent i = new Intent(actionCode);
if (media == MEDIA_VIDEO) {
i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
}
startActivityForResult(i, requestCode);
}
/*
* Handle the activity result
*
* @see android.app.Activity#onActivityResult(int, int,
* android.content.Intent)
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//super.onActivityResult(requestCode, resultCode, intent);
Log.d("MYDEBUGGING", "Handling activity result. requestCode:" + requestCode + " resultCode:" + resultCode);
if (resultCode == Activity.RESULT_CANCELED) {
pic_upload_button.setEnabled(true);
video_upload_button.setEnabled(true);
fileType = "none";
showToast(this, "Request canceled, Touch the picture or image button to try again");
return;
}
switch (requestCode) {
case CAMERA_PIC_REQUEST:
switch (resultCode) {
case Activity.RESULT_OK:
postType = requestCode;
fileType = "picture";
// Seems that this is the only way to be sure I end up with an actual file.
filePath = getRealPathFromURI(intent.getData());
if (filePath != null) {
showToast(this, "Image ready to be shared");
} else {
showToast(this, "Something went wrong. Image could not be captured.");
}
break;
default:
alert("Activity failed", "Could not create picture file", this);
}
break;
case CAMERA_VID_REQUEST:
switch (resultCode) {
case Activity.RESULT_OK:
postType = requestCode;
fileType = "video";
// Seems that this is the only way to be sure I end up with a video file.
filePath = getRealPathFromURI(intent.getData());
if (filePath != null) {
showToast(this, "Video ready to be shared");
} else {
showToast(this, "Something went wrong. Video could not be captured.");
}
break;
default:
alert("Activity failed", "Could not create video file", this);
}
break;
}
}
fileType и postType являются глобальными для класса и используются для указания загрузчику http, какой тип файла отправлять. actionCode является либо MediaStore.ACTION_VIDEO_CAPTURE, либо MediaStore.ACTION_IMAGE_CAPTURE в зависимости от выбора пользователя.
Есть мысли?