Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

EncodedImage.createEncodedImage() = null

Hi all,

 

Working on: 5.0 OS

 

Iam trying to construct a bitmap image using EncodedImage. I am retriving hte byte array from teh SQLite database. 

 

 

String str1 = "SELECT BarCodeImage FROM  CM_INTROPAGE where IntroPageId  = '10180'";

String str2 = DatabaseFunctions.getDatavalue(str1); byte[] imgBytes = str2.getBytes();
if(imgBytes !=null) { Tools.printMessage("Imgbytes != null, if block" + imgBytes.length); try { bitmap1 = EncodedImage.createEncodedImage(imgBytes , 0, imgBytes.length, null); } catch(Exception e) { Tools.printMessage("Error EncodedImage..... " + e.getMessage()); } Tools.printMessage("bitmap1 is created, if block"); bmp_Barcode = bitmap1.getBitmap(); Tools.printMessage("bmp_Barcode is created, if block"); } else { bmp_Barcode= Bitmap.getBitmapResource("barcode.png"); Tools.printMessage("bmp_Barcode is created, else block"); }

 

the following is the output

 


mgbytes != null, if block 32987

Error EncodedImage..... null

 

I have other quries that are retrieving the bytes, and constructing the images in a nice manner.

but coming to this it is not working  and is throwing the above exception. am unable to figure out why it is "null", what does null mean here???

 

am doing anything wrong??

 

anybody having similar kind of results??

Thanks and Regards,
PraveenGoparaju.
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: EncodedImage.createEncodedImage() = null

It would probablyhelp if you printed out the error message (use toString and not getMessage so that it prints out what type of exception it is). I would guess the error is because it cant determine what type of image it is that you are trying to create from the data.

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: EncodedImage.createEncodedImage() = null

The problem may lie in an encoding mess-up retrieving data from your database. I would suggest trying to have a static image already not in your database and try and get an EncodedImage and ensure that this works correctly first, then tell us what your database schema is if you're still having trouble as well, as well as what exact exception you are getting.

 

 

Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: EncodedImage.createEncodedImage() = null

Hi,

 

@yadarishy, the code that is retriving teh byte array is fine, I guess, because it is working for few images and not working for this image data.

 

the image data is of type 'blob'.

 

@CMY, null is the exception throwing...

 

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: EncodedImage.createEncodedImage() = null

Hi CMY,

 

as you said i traced the error message... and it is throwing the IllegalArgumentException.

 

 

In catch Block Error EncodedImage..... java.lang.IllegalArgumentException

 

 

so i think the img bytes are of a unsupported format.

 

any ideas to fix this? do i need to request the client to upload only the supported formats? or do we have any workaround to make work??

 

Help!!!

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: EncodedImage.createEncodedImage() = null

use only supported format

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: EncodedImage.createEncodedImage() = null

Hi simon and all,

 

just to confirm, in encodedImage context, is there any chance to throw  java.lang.IllegalArgumentException,  other than unsupported format??


I mean if the data is corrupted while saving to the database, or while retrieving?

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: EncodedImage.createEncodedImage() = null

sure. you get it whenever the array does not contain the byte data of a supported image.

for example when you download an image directly and get a http response message instead.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: EncodedImage.createEncodedImage() = null

Hi simon,

 

i think it is of something is going.. because i just verified the site, and it allows only .png, .jpg files. other types are not supported.

 

may be there is an error while downloading, or saving or retrieving i guess.

 

am doing in the following way to save the data...

 

1) the data is saving to a string.

 

2) am saving to the database, by retrieving these image bytes from string.

 

3) then again from teh database, am retrieving these bytes.

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: EncodedImage.createEncodedImage() = null

i would suggest to use

IOUtilities.streamToBytes to read the file into a byte array and save this - only with httpresponsecode==200 of course.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter