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

BlackBerry® World™ Development

Reply
New Contributor
Posts: 9
Registered: ‎03-15-2010
My Device: 9700 & jde 4.7
My Carrier: Software Engineer

illegalArgument Exception while retrieve contacts image and display in my application.

Hi ,

 

I would like to retrieve all the contacts  "Name"  and their "associated image" . I have successfully retrieve the name but when i am trying to retrieve image and want to convert the byte array in Bitmap.  I am getting an illegalArgument Exception . Following is the code I am using :-

 

if (contactList.isSupportedField(Contact.PHOTO)) {
           if (c.countValues(Contact.PHOTO) > 0) {
           photoEncoded = c.getBinary(Contact.PHOTO, 0);

        bmap = Bitmap.createBitmapFromBytes(photoEncoded,0,photoEncoded.length,1 );
}

 

Can anyone help me PLS !!

 

Thanks in advance .

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: illegalArgument Exception while retrieve contacts image and display in my application.

From the Javadocs:

 

 


 

getBinary
public byte[] getBinary(int field,
int index)

Returns a byte array containing a binary representation of the data within the given field.

The PIMList.isSupportedField(int) should be used to verify the validity of the field before invoking this method.

Parameters: field - An integer representing the field for which to return the binary representation. index - An integer representing the index of the data within the field. Returns: A byte array containing the binary representation ("B" binary encoded string) of the data within this field. Since: JDE 4.0.0

 

 


 

 

I don't see this in your snippet. It may be that the operation is unsupported, and you are getting an invalid byte [], which would cause the Exception you're seeing.

 

Hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
New Contributor
Posts: 9
Registered: ‎03-15-2010
My Device: 9700 & jde 4.7
My Carrier: Software Engineer

Re: illegalArgument Exception while retrieve contacts image and display in my application.

Hi ,

 

I am checking the support of photo field in a if condition , before invoking the getBinary method, However , I am still getting the exception.

 

 if (contactList.isSupportedField(Contact.PHOTO))

 

Pls help !!!

 

Thanks in advance

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: illegalArgument Exception while retrieve contacts image and display in my application.

Right, I'm blind XD Sorry...

 

Have you tried other approaches? If your photo is a PNG, there's a createBitmapFromPNG method...

 

createBitmapFromPNG
public static Bitmap createBitmapFromPNG(byte[] png,
int offset,
int length)
Creates a bitmap from provided PNG format data. Parameters: png - PNG data. offset - Start of PNG data in the passed byte array. length - Length of PNG data in the passed byte array: -1 means to the end of the data array. Returns: New Bitmap object. Throws: OutOfMemoryError - Thrown if insufficient memory to process the PNG data into a bitmap. NullPointerException - Thrown if the png parameter is null. IllegalArgumentException - Thrown if the png parameter is invalid, or offset or length are invalid.

Hope that helps,

~Dom

 

----------------------------------------------------------------------------
chown -R us ./base
~J!NX