1

I recently got a crash report in an Android App that takes photographs and saves them on SD card. I tried to reproduce it, but it was unsuccessful. The stack trace is the following

> java.lang.NullPointerException at
> java.io.FileOutputStream.write(FileOutputStream.java:256) at
> com.infobest.slices.SlicesActivity$1.onPictureTaken(SlicesActivity.java:115)
> at android.hardware.Camera$EventHandler.handleMessage(Camera.java:562)
> at android.os.Handler.dispatchMessage(Handler.java:99) at
> android.os.Looper.loop(Looper.java:130) at
> android.app.ActivityThread.main(ActivityThread.java:3683) at
> java.lang.reflect.Method.invokeNative(Native Method) at
> java.lang.reflect.Method.invoke(Method.java:507) at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) at
> dalvik.system.NativeStart.main(Native Method)

The exception is triggered here:

private PictureCallback mPicture = new PictureCallback()
    {

        public void onPictureTaken(byte[] data, Camera camera)
        {
                            (...)       
 File pictureFile = PicturePathProvider.getInstance().getOutputMediaFile(MEDIA_TYPE_IMAGE, mSession.getPath());
                        if (pictureFile == null)
                        {
                            (...)
                        }
                        else
                        {
                            (...)
                                FileOutputStream fos = new FileOutputStream(pictureFile);
                                fos.write(data);
                                fos.close();
                            (...)

The (...) are toasts and logs (no majour operations/actions done). It is just an isolated case, but I wonder what could be the reasons for this to happen. Thank you! :)

4

1 回答 1

0

Check the "data" array against null, it is possible to be null.

于 2013-04-04T12:33:10.447 回答