谁可以帮我检查这个错误,我在我的活动中使用startActivityForResult(用相机拍照)。拍完照片后,我的活动无法恢复。 :(
java.lang.RuntimeException: Unable to resume activity {com.example/com.example.view.main.PersonActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=998, result=-1, data=null} to activity {com.example/com.example.view.main.PersonActivity}: java.lang.NullPointerException
--------- Stack trace ---------
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2458)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
android.app.ActivityThread.access$600(ActivityThread.java:128)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4514)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
dalvik.system.NativeStart.main(Native Method)
-------------------------------
--------- Cause ---------
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=998, result=-1, data=null} to activity {com.example/com.example.view.main.PersonActivity}: java.lang.NullPointerException
android.app.ActivityThread.deliverResults(ActivityThread.java:2994)
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2445)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
android.app.ActivityThread.access$600(ActivityThread.java:128)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4514)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
dalvik.system.NativeStart.main(Native Method)
-------------------------------
在我的Java代码中,在OnActivityResult方法中。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String filePath = "";
switch (requestCode) {
case MyActivity.RQ_SALE_TAKE_PHOTO:
{
if (resultCode == RESULT_OK) {
if (data != null && data.getExtras() != null && data.getAction() != null) {
Bitmap tempBitmap = null;
tempBitmap = (Bitmap) data.getExtras().get("data");
//.....
}
} else {
//DO SOMETHING HERE
}
}
break;
}
}
代码调用摄像头:
public static File takePhoto(Activity sender, int requestCode) {
System.gc();
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String fileName = Constants.TEMP_IMG + "_" + DateUtils.getCurrentDateTimeWithFormat(null) + ".jpg";
File retFile = new File(ExternalStorage.getTakenPhotoPath(sender), fileName);
if (!retFile.exists())
try {
retFile.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(retFile));
sender.startActivityForResult(intent, requestCode);
return retFile;
}
有人能帮我解释上述错误,并告诉我如何修复这个错误吗?