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
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: Program not response when try to get image from URL

I think you're going about this a litttle incorrectly. What you probably want to do is:

-Collect your items and start a Timer to add your downloads each to a TimerTask (if you have a lot of items you can exhaust your number of threads). You can have a couple Timers if you need them.

-Create your list and when you're painting the row wait and see if your Bitmap for that item is null. If it is don't draw, but if it isn't then do the drawing (probably the cause of your NullPointerException).

-As your downloads finish you can call invalidate() on your ListField so it can redraw with the images

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: Program not response when try to get image from URL

No, you don't want your downloads in TimerTasks - their run() methods should never make blocking calls (which the downloads are all about). Refer to java.util.Timer docs for more info about that.

 

Read the following thread for some ideas on organizing image downloads:

IllegalArgumentException Loading Image from Server

 

There are quite detailed explanations near the end of the thread.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: Program not response when try to get image from URL

I had read previously from someone here in the forums that a TimerTask (for them specifically, not a general one that performs other tasks) is the way to do it so you don't create too many Threads and end up losing downloads. If you have like 30 downloads something is going to get blocked regardless, at least with this you control that it's something as non-critical as an image.

Please use plain text.
Regular Contributor
gillaraz
Posts: 69
Registered: 10-19-2010

Re: Program not response when try to get image from URL

[ Edited ]

Hmm so confusing now.

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: Program not response when try to get image from URL

Well - putting downloads in TimerTask is obviously wrong, as their run() methods "should complete quickly" (quotation from the java.util.Timer Javadoc). Blocking calls by their nature do not "complete quickly". And any network activity (as well as filesystem!) is blocking.

 

Since, as you correctly stated, one cannot create Threads with impunity, the only proper solution becomes doing those downloads in one Thread, one-by-one. That is exactly what I've suggested in the thread referenced above.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: Program not response when try to get image from URL

I agree with you on the should complete quickly part, however the reason as far as I can tell from the docs is so other Tasks don't get thrown off schedule because of one Task taking too much time. I suppose the way I'm programming it is essentually a queue, but it behaves completely how I would expect and want. We are really implementing the same thing since one Timer == one Thread and each download would block the subsequent ones, I'm just not adhering to the guidelines as much since I know what it's doing and how it's going to respond.

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: Program not response when try to get image from URL

This would appear to be a duplicate?

 

http://supportforums.blackberry.com/t5/Java-Development/Problem-with-Fetch-Content-and-Thumbnail-ima...

 

Original Poster, can you confirm these are the same problem and terminate one of the Threads?

Please use plain text.