“未能传递结果”由于尝试图像捕获时摩托罗拉 Bravo 上的 ManagedQuery 中存在 NPE。在 Evo 上运行良好

发布于 2024-10-29 04:25:13 字数 6299 浏览 6 评论 0原文

获取 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);
}

这是经过清理的相关代码(刚刚删除了客户端信息)

/*
 * 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,具体取决于用户选择。

有什么想法吗?

Getting java.lang.RuntimeException: Failure delivering result ResultInfo from a NPE apparently resulting from a call in my getRealPathFromURI function.

Video capture works fine, but image capture throws the NPE. Both image and video work fine on my 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)

Here's the relevant function:

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);
}

Here's sanitized relevant code (just removed client info)

/*
 * 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 and postType are global to the class and are used to indicate to the http uploader what type of file to send. actionCode is either MediaStore.ACTION_VIDEO_CAPTURE or MediaStore.ACTION_IMAGE_CAPTURE depending on user selection.

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过气美图社 2024-11-05 04:25:13

我的猜测是 contentUri 或文件类型值不正确,因此 ManagedQuery 调用失败。

My guess is that the contentUri or filetype values aren't correct, so the managedQuery call fails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文