开发者

Why is decodeByteArray giving me a null pointer error

I'm trying to pass a byte array from an image to an activity through a bundle

creating the byte array with

            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream picArray = new ByteArrayOutputStream(); 
            thumbnail.compress(CompressFormat.PNG, 0, picArray); 
            byte[] picData = picArray.toByteArray();

when i try to decode the byte array into a bitmap i get a null pointer exception which FC's (running on physical phone)

I've been going through line by line and this is the only thing creating an error

            //grab byte array taken
            Intent sent = this.getIntent();
            Bundle arrayForPic = sent.get开发者_高级运维Extras();
            byte[] picArray = arrayForPic.getByteArray("pictureArray");

            //convert array into bitmap
            //null error happens HERE
            Bitmap thumbnail = BitmapFactory.
               decodeByteArray(picArray, 0, picArray.length);

the errors are

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.HandlePic}: java.lang.NullPointerException


Caused by: java.lang.NullPointerException
at com.test.HandlePic.onCreate(HandlePic.java:43)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1703)

line 43 is where the decodeByteArray is


I would guess that picArray is null. Presumably because there is no pictureArray value in the bundle. You should be able to step through the code with a debugger to see exactly what is going wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜