Java &引用;“未能交付结果”;由于尝试图像捕获时摩托罗拉Bravo上managedQuery中出现NPE。在Evo上运行良好

Java &引用;“未能交付结果”;由于尝试图像捕获时摩托罗拉Bravo上managedQuery中出现NPE。在Evo上运行良好,java,android,android-camera,image-capture,Java,Android,Android Camera,Image Capture,获取java.lang.RuntimeException:从NPE传递结果ResultInfo失败,这显然是由于调用了我的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/Andro

获取java.lang.RuntimeException:从NPE传递结果ResultInfo失败,这显然是由于调用了我的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);
}
以下是经过消毒的相关代码(刚刚删除了客户信息)

fileType和postType对于类是全局的,用于向http上载程序指示要发送的文件类型。actionCode是MediaStore.ACTION\u视频捕获或MediaStore.ACTION\u图像捕获,具体取决于用户选择


有什么想法吗?

我猜contentUri或filetype值不正确,因此managedQuery调用失败。

在调用
getRealPathFromUri
之前,先放入一条日志语句,然后输出
intent.getData()
的值。根据您描述的问题,我认为URI为null,或者您的游标为null。编辑:没有看到代码中的“此处存在…”注释。在这种情况下,URI为null或数据库出现问题(可能已关闭)。要感谢Bob提供的帮助。谢谢--------8<来自聊天室8
/*
 * 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;
    }
}