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
Contributor
jiten_jk
Posts: 13
Registered: ‎09-16-2011
My Device: Black berry 9800/ Blackberry 6
My Carrier: BSNL/Airtel
Accepted Solution

changing the text of a Labelfield while it is on diplay stack .

[ Edited ]

Hi,

 

I have a TimerTask which changes the text of a label field at regular interval,  but I am getting the IllegalStateException,

 

can any one let me know where am i going wrong? what silly mistake am I doing????

 

 

public final class MyScreen extends MainScreen
{
    LabelField lbf;
    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {        
           
        setTitle("MyTitle");
        
       Timer t1= new Timer();
       Timer t2=new Timer();
     
       double rate=3600.0/3600;
       double total=0.0;
      final MyTimerTask mtask=new MyTimerTask(rate, total);
     
       lbf=new LabelField();
       
       TimerTask tt=new TimerTask(){
           public void run(){
             System.out.println("inside the timer task tt");
             lbf.setText(Double.toString(mtask.getTotal()));
            
               
           }
       };
      
       t1.scheduleAtFixedRate(mtask, 0, 1000);
       t2.scheduleAtFixedRate(tt, 0,1000);
       add(lbf);
    }
}


Please use plain text.
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Bold
My Carrier: Airtel

Re: changing the text of a Labelfield while it is on diplay stack .

Hi, Jiten

 

use UiApplication.getEventlock() while updating Ui from non event thread like this

 

 TimerTask tt=new TimerTask(){
           public void run(){
              synchronized (UiApplication.getEventLock())
              {
                  System.out.println("inside the timer task tt");
                  lbf.setText(""+i++);    
            }
                     
           }

 

Thanks.

Please use plain text.
Contributor
bratbiswas
Posts: 10
Registered: ‎12-26-2011
My Device: 9000
My Carrier: Vodafone IN

Re: changing the text of a Labelfield while it is on diplay stack .

Or use UiApplication.invokeLater() or UiApplication.invokeAndWait() to get this done by the event thread of the application. See this article.

Please use plain text.
Contributor
jiten_jk
Posts: 13
Registered: ‎09-16-2011
My Device: Black berry 9800/ Blackberry 6
My Carrier: BSNL/Airtel

Re: changing the text of a Labelfield while it is on diplay stack .

Thanks,

 

lettting me know where i was wrong.

Please use plain text.