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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Contributor
zapatista
Posts: 5
Registered: ‎06-08-2012
My Carrier: INDOSAT

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 ?

Please use plain text.
Developer
simon_hain
Posts: 14,064
Registered: ‎07-29-2008
My Carrier: O2 Germany

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
Please use plain text.
New Contributor
zapatista
Posts: 5
Registered: ‎06-08-2012
My Carrier: INDOSAT

Re: bitmaps array in ListField

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

Please use plain text.
Developer
simon_hain
Posts: 14,064
Registered: ‎07-29-2008
My Carrier: O2 Germany

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
Please use plain text.