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
New Contributor
Posts: 5
Registered: ‎06-08-2012
My Device: Curve 8520

bitmaps array in ListField

i want to create a list of images (image 0.png, 1.jpg, 2.gif etc.) and i want to put them in a ListField, in a thread i have the following

JSONArray resImage = new JSONArray(getJsonresponse("http://localhost/blackberry/sampledata.json"));
int chkImg = resImage.length();
_bitmap = new Bitmap[chkImg];
for (int x = 0; x < chkImg; x++) {
    _bitmap[x] = connectServerForImage(resImage.getJSONObject(x).getString("image_url"));
}

 

public void drawListRow (ListField listField, Graphics g, int index, int y, int w) {
    g.drawBitmap(xText, y + yText, 80, 200, _bitmap[index], 0, 0);
}

 but it throws null exception, how to get bitmap array in drawListRow ?

Developer
Posts: 16,500
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: bitmaps array in ListField

do you execute your networking on a separate thread? (as you should)
check
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

most likely the download of the bitmaps is not finished yet when you try to access them. Or the variable is null, difficult to say with this code snippet.
----------------------------------------------------------
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
New Contributor
Posts: 5
Registered: ‎06-08-2012
My Device: Curve 8520

Re: bitmaps array in ListField

Yes, my networking on a separate thread. Is this the proper way to make a list of images?

Developer
Posts: 16,500
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: bitmaps array in ListField

personally i would check for more anomalies (something null etc), but per se the method is fine, yes.
is the downloading working good? check the contents with the debugger.
----------------------------------------------------------
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