当用户拍照时按后退按钮时程序崩溃

发布于 2024-11-17 11:59:24 字数 2078 浏览 0 评论 0原文

我正在使用意图,我想知道为什么当他们按下后退按钮时我的应用程序不断崩溃。我已经尝试过:

if(data.getExtras() != null)

但仍然不起作用。有更正确的方法来做到这一点吗?

哎呀,很抱歉没有具体说明。 D:

堆栈跟踪:

E/AndroidRuntime(19352): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=0, data=null} to activity {com.smilingdevil.Day5/com.smilingdevil.Day5.BopActivity}: java.lang.NullPointerException
E/AndroidRuntime(19352):        at android.app.ActivityThread.deliverResults(ActivityThread.java:2883)
E/AndroidRuntime(19352):        at android.app.ActivityThread.handleSendResult(ActivityThread.java:2925)
E/AndroidRuntime(19352):        at android.app.ActivityThread.access$2000(ActivityThread.java:132)
E/AndroidRuntime(19352):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1063)
E/AndroidRuntime(19352):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19352):        at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime(19352):        at android.app.ActivityThread.main(ActivityThread.java:4196)
E/AndroidRuntime(19352):        at java.lang.reflect.Method.invokeNative(NativeMethod)
E/AndroidRuntime(19352):        at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(19352):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(19352):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(19352):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(19352): Caused by: java.lang.NullPointerException
E/AndroidRuntime(19352):        at com.smilingdevil.Day5.BopActivity.onActivityResult(BopActivity.java:167)
E/AndroidRuntime(19352):        at android.app.Activity.dispatchActivityResult(Activity.java:4010)
E/AndroidRuntime(19352):        at android.app.ActivityThread.deliverResults(ActivityThread.java:2879)
E/AndroidRuntime(19352):        ... 11 more
W/ActivityManager( 1337):   Force finishing activity com.smilingdevil.Day5/.BopActivity

I'm using intents and I'm wondering why my application keeps crashing when they press the back button. I have tried:

if(data.getExtras() != null)

but that still doesn't work. Is there a more correct way to do this?

Oops, sorry for not being specific. D:

Stacktrace:

E/AndroidRuntime(19352): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=0, data=null} to activity {com.smilingdevil.Day5/com.smilingdevil.Day5.BopActivity}: java.lang.NullPointerException
E/AndroidRuntime(19352):        at android.app.ActivityThread.deliverResults(ActivityThread.java:2883)
E/AndroidRuntime(19352):        at android.app.ActivityThread.handleSendResult(ActivityThread.java:2925)
E/AndroidRuntime(19352):        at android.app.ActivityThread.access$2000(ActivityThread.java:132)
E/AndroidRuntime(19352):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1063)
E/AndroidRuntime(19352):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19352):        at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime(19352):        at android.app.ActivityThread.main(ActivityThread.java:4196)
E/AndroidRuntime(19352):        at java.lang.reflect.Method.invokeNative(NativeMethod)
E/AndroidRuntime(19352):        at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(19352):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(19352):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(19352):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(19352): Caused by: java.lang.NullPointerException
E/AndroidRuntime(19352):        at com.smilingdevil.Day5.BopActivity.onActivityResult(BopActivity.java:167)
E/AndroidRuntime(19352):        at android.app.Activity.dispatchActivityResult(Activity.java:4010)
E/AndroidRuntime(19352):        at android.app.ActivityThread.deliverResults(ActivityThread.java:2879)
E/AndroidRuntime(19352):        ... 11 more
W/ActivityManager( 1337):   Force finishing activity com.smilingdevil.Day5/.BopActivity

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

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

发布评论

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

评论(2

眼波传意 2024-11-24 11:59:24

您是否使用 onactivityResult(int requestCode, int resultCode, Intent data) 方法处理调用相机 Intent 的结果?

如果是这样,请确保您正在检查 resultCode -

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // first, check that your requestCode matches the requestCode you sent to the
    // camera intent - this should really only matter if you're making multiple 
    // requests to an intent and expecting to do different things with the returns,
    // but you should check anyway.
    if (requestCode == whateverCodeYouUsedInRequest) {
        if (resultCode == RESULT_OK) {
            // everything should be OK and you can process the expected result

        } else if (resultCode == RESULT_CANCELED) {
            // user explicitly canceled the called activity - you shouldn't 
            // expect to process the expected result.
        } else {
            // not sure what happened here - but result isn't 'RESULT_OK' so 
            // you shouldn't expect to process the expected result.
        }
    }
}

Are you handling the result of calling the camera intent with the onactivityResult(int requestCode, int resultCode, Intent data) method?

If so, make sure you're checking the resultCode -

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // first, check that your requestCode matches the requestCode you sent to the
    // camera intent - this should really only matter if you're making multiple 
    // requests to an intent and expecting to do different things with the returns,
    // but you should check anyway.
    if (requestCode == whateverCodeYouUsedInRequest) {
        if (resultCode == RESULT_OK) {
            // everything should be OK and you can process the expected result

        } else if (resultCode == RESULT_CANCELED) {
            // user explicitly canceled the called activity - you shouldn't 
            // expect to process the expected result.
        } else {
            // not sure what happened here - but result isn't 'RESULT_OK' so 
            // you shouldn't expect to process the expected result.
        }
    }
}
情感失落者 2024-11-24 11:59:24

你正在崩溃,因为数据为空。您需要检查 if(data != null && data.getExtras() != null)。无法保证已完成的活动已包含任何数据作为设置其结果的一部分。

You're crashing because data is null. You need to do the check if(data != null && data.getExtras() != null). There is no guarantee that the activity that has finished has included any data as part of setting its result.

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