在我的 android 应用程序中,我需要调用标准照片应用程序,拍摄照片并将其存储在设备的 sqlite 数据库中。
这是我启动意图的按钮的处理程序
private Uri fileUri;
private File file;
private ImageView foto;
public void fotoHandler(View view) {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = FileUtilities.getOutputMediaFile();
fileUri = Uri.fromFile(file); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, TAKE_PICTURE);
}
这是结果处理程序
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Image saved to:\n" +
fileUri.toString(), Toast.LENGTH_LONG).show();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), fileUri);
file.delete();
foto.setImageBitmap(laatsteFoto);
} catch (FileNotFoundException e) {
Toast.makeText(this, "File " + fileUri.toString() + " can't be found !", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "File " + fileUri.toString() + " can't be read !", Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else
Toast.makeText(this, "Error during retrieving photo from camera !", Toast.LENGTH_LONG).show();
}
}
它在我的带有 ICS 的 Acer A100 上运行良好,但在带有 ICS 的三星 Galaxy S2 上出现问题。
10-24 08:44:05.190: E/AndroidRuntime(19861): FATAL EXCEPTION: main
10-24 08:44:05.190: E/AndroidRuntime(19861): java.lang.RuntimeException: Unable to resume activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.NullPointerException
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2455)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2483)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1997)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3362)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.access$700(ActivityThread.java:127)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.os.Looper.loop(Looper.java:137)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.main(ActivityThread.java:4511)
10-24 08:44:05.190: E/AndroidRuntime(19861): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 08:44:05.190: E/AndroidRuntime(19861): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 08:44:05.190: E/AndroidRuntime(19861): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-24 08:44:05.190: E/AndroidRuntime(19861): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-24 08:44:05.190: E/AndroidRuntime(19861): at dalvik.system.NativeStart.main(Native Method)
10-24 08:44:05.190: E/AndroidRuntime(19861): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.NullPointerException
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.deliverResults(ActivityThread.java:2991)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2442)
10-24 08:44:05.190: E/AndroidRuntime(19861): ... 13 more
10-24 08:44:05.190: E/AndroidRuntime(19861): Caused by: java.lang.NullPointerException
10-24 08:44:05.190: E/AndroidRuntime(19861): at be.lengo.autikoken.IngredientWijzigen.onActivityResult(IngredientWijzigen.java:233)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.Activity.dispatchActivityResult(Activity.java:4654)
10-24 08:44:05.190: E/AndroidRuntime(19861): at android.app.ActivityThread.deliverResults(ActivityThread.java:2987)
10-24 08:44:05.190: E/AndroidRuntime(19861): ... 14 more
当我用结果评论吐司时记录
10-24 09:27:06.520: E/AndroidRuntime(21849): FATAL EXCEPTION: main
10-24 09:27:06.520: E/AndroidRuntime(21849): java.lang.RuntimeException: Unable to resume activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.NullPointerException
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2455)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2483)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1997)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3362)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.access$700(ActivityThread.java:127)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.os.Looper.loop(Looper.java:137)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.main(ActivityThread.java:4511)
10-24 09:27:06.520: E/AndroidRuntime(21849): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 09:27:06.520: E/AndroidRuntime(21849): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 09:27:06.520: E/AndroidRuntime(21849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-24 09:27:06.520: E/AndroidRuntime(21849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-24 09:27:06.520: E/AndroidRuntime(21849): at dalvik.system.NativeStart.main(Native Method)
10-24 09:27:06.520: E/AndroidRuntime(21849): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {be.lengo.autikoken/be.lengo.autikoken.IngredientWijzigen}: java.lang.NullPointerException
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.deliverResults(ActivityThread.java:2991)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2442)
10-24 09:27:06.520: E/AndroidRuntime(21849): ... 13 more
10-24 09:27:06.520: E/AndroidRuntime(21849): Caused by: java.lang.NullPointerException
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.content.ContentResolver.openInputStream(ContentResolver.java:361)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:715)
10-24 09:27:06.520: E/AndroidRuntime(21849): at be.lengo.autikoken.IngredientWijzigen.onActivityResult(IngredientWijzigen.java:236)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.Activity.dispatchActivityResult(Activity.java:4654)
10-24 09:27:06.520: E/AndroidRuntime(21849): at android.app.ActivityThread.deliverResults(ActivityThread.java:2987)
10-24 09:27:06.520: E/AndroidRuntime(21849): ... 14 more