0

i am writing a standart app which takes photo and then save it to the phone , as soon as i hit the save button, it saves the image, but crashes with Force Close , i read at least 10-15 threads here for the same issue, but none of them helped.I am testing on Samsung Galaxy S

here is the intent

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg";  

File imageFile = new File(imageFilePath); 
Uri imageFileUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,imageFileUri );
startActivityForResult(cameraIntent, 1337); 

also the OnActivity

protected void onActivityResult (int requestCode, int resultCode, Intent data) {  
super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) 
    {  

     BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
     bmpFactoryOptions.inJustDecodeBounds = false;  
     Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
     image.setImageBitmap(bmp);
     }
    }       

thanks in advance

here is the LogCat

06-21 13:07:09.421: D/AndroidRuntime(18525): Shutting down VM
06-21 13:07:09.421: W/dalvikvm(18525): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-21 13:07:09.421: E/AndroidRuntime(18525): FATAL EXCEPTION: main
06-21 13:07:09.421: E/AndroidRuntime(18525): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=-1, data=null} to activity {com.example.testnewbutton/com.example.testnewbutton.MainActivity}: java.lang.NullPointerException
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.app.ActivityThread.access$2000(ActivityThread.java:117)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.os.Looper.loop(Looper.java:130)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at android.app.ActivityThread.main(ActivityThread.java:3687)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at java.lang.reflect.Method.invokeNative(Native Method)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at java.lang.reflect.Method.invoke(Method.java:507)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-21 13:07:09.421: E/AndroidRuntime(18525):    at dalvik.system.NativeStart.main(Native Method)
06-21 13:07:09.421: E/AndroidRuntime(18525): Caused by: java.lang.NullPointerException

BackSlash
  • 21,927
  • 22
  • 96
  • 136
shang tsung
  • 161
  • 3
  • 9
  • 2
    Post the LogCat please. – BackSlash Jun 21 '13 at 10:03
  • 06-21 13:07:09.421: E/AndroidRuntime(18525): FATAL EXCEPTION: main 06-21 13:07:09.421: E/AndroidRuntime(18525): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=-1, data=null} to activity {com.example.testnewbutton/com.example.testnewbutton.MainActivity}: java.lang.NullPointerException – shang tsung Jun 21 '13 at 10:10
  • http://stackoverflow.com/questions/3275749/im-getting-a-nullpointerexception-when-i-use-action-image-capture-to-take-a-pic – Dimmerg Jun 21 '13 at 10:24

1 Answers1

0

It's hard to say what the issue is without seeing your LogCat. However, it looks like you're taking a photo with the camera and loading it at full resolution. The Galaxy S has a 5 MP camera.

(((2592 * 1944 * 32) / 8) / 1024) / 1024 = 19.22 MB. You could be running into an OutOfMemoryError.

Take a look here for advice on how to avoid this.

MaxAlexander
  • 460
  • 3
  • 10