Possible Duplicate:
I'm getting a NullPointerException when I use ACTION_IMAGE_CAPTURE to take a picture
I have some code.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); File photo = new File(CamDir, filename); imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); startActivityForResult(intent, 0); public void onActivityResult(int requestCode, int resultCode, Intent data) { Bitmap bitmap = null; if (resultCode == Activity.RESULT_OK && requestCode == 0) { Uri selectedImage = imageUri; ContentResolver cr = getContentResolver(); bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage); } 1.the phone in vertical position.
2.start the application.
3.press the button to take a photo.
4.press Ok. (save photo)
Everything fine.
1.the phone in vertical position.
2.start the application.
3.press the button to take a photo.
4.rotate the phone to horizontal position.
5.press Ok. (save photo)
Have error
E/AndroidRuntime(22779): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity com.photo/com.photo.PhotoActivity}: java.lang.NullPointerException I think when I rotate the phone to horizontal position intent was reloaded, and camera not
know where to send results.
How to fix this problem.
Solution:
onActivityResult(...){ ... reload() } public void reload() { Intent intent = getIntent(); overridePendingTransition(0, 0); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); overridePendingTransition(0, 0); startActivity(intent); }