2011-06-29 152 views
1

我正在使用意图,我想知道为什么我的应用程序在按下后退按钮时会一直崩溃。我曾尝试过:当用户在拍照时按下后退按钮时,程序崩溃

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 
+1

你得到了什么错误? –

+0

请发布您的崩溃logcat跟踪。 – yep

+0

对不起,已经有一段时间了。增加了一个堆栈跟踪。 –

回答

1

你处理调用带onactivityResult(int requestCode, int resultCode, Intent data)方法的相机意图的结果呢?

如果是这样,请确保您正在检查的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. 
     } 
    } 
} 
+0

谢谢! :D *检查* –

1

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

相关问题