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 Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified
Accepted Solution

setImage

I use a method in my thread named callBack.

 

public void callback(final String data)  
    {  
         if (data.startsWith("Exception")) return;  
   
         
             byte[] dataArray = data.getBytes();  
             bitmap = EncodedImage.createEncodedImage(dataArray, 0,  
                     dataArray.length);   
             /*
             if (bitmap != null)
             {
            	 inform = "";
            	 invalidate();
             }*/
             setImage(bitmap); 
        
     }

 When i use thread.run() it ok. But thread.start() can not display image and throw an exception at setImage line. Somebody know the reason? I confirmed the data is load success because i had printed the length of data and compare in two situation. They are same.

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: setImage

When you call Thread.run(), you are just executing the run() method using your own calling thread.

 

Whan you call Thread.start(), you are starting a separate thread.

 

You cannot access the UI from a non-event thread. So, from you non-even thread you must synchronize with the event lock, or place your work in the event queue for processing by your event thread.

 

See the API docs for UiApplication.invokeLater(). This is what would suggest for what you are trying to accomplish.

 

 

Highlighted
New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: setImage

Year. I found a Thread similar :  http://rim.lithium.com/t5/Java-Development/Threads/m-p/195476 after see the exception.

 

So resolved.