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
Posts: 27
Registered: ‎05-10-2012
My Device: bold 9700
My Carrier: Vodafone

Calling invalidate to repaint screen gives an error inside of a TimerTask instance.

Hi Guys,

 

Basic one here..

I am trying to paint to my screen on a timer, what happens is i press a key on my phone

it uses invalidate and draws an item to the screen, 5 seconds after it is pressed I then want another 

item drawed on the screen, but calling invalidate inside of this timertask does not seem to 

work at all for some reason. 

 

heres a short snippet. .

 

 TimerTask mTimerTask = new TimerTask() {
		  

		  
		   public void run() {
			   Random gen = new Random();
			   int a = isUsed1.size();

			 int generatedIndex = gen.nextInt(a);
		     int element = isUsed1.elementAt(generatedIndex);
			  // Dialog.inform( "Hello " + Integer.toString(a));
			  // System.out.println(Integer.toString(a));
	          switch(element)
	          {
	          case 0:
	        	  isEpressComputer = true;
	        	  
	        	  updateDisplay();
	        	  invalidate();

	          case 1:
	        	  isDpressComputer = true;
	        	  
	        	  updateDisplay();
	        	  invalidate();
	        	  
	          case 2:
	        	  isXpressComputer = true;
	        	
	        	  updateDisplay();
	        	  invalidate();

	          case 3:
	        	  isRpressComputer = true;
	        	 
	        	  updateDisplay();
	        	  invalidate();

	          case 4:
	        	  isFpressComputer = true;
	        	  
	        	  updateDisplay();
	        	  invalidate();

	          case 5:
	        	  isCpressComputer = true;
	        	 
	        	  updateDisplay();
	        	  invalidate();

	          case 6:
	        	  isTpressComputer = true;
	        	
	        	  updateDisplay();
	        	  invalidate();
	          case 7:
	        	  isGpressComputer = true;
	        	  
	        	  updateDisplay();
	        	  invalidate();
	          case 8:
	        	  isVpressComputer = true;
	        	  
	        	  updateDisplay();
	        	  invalidate();
	        	  default:
	        		  
}
	        }
	    };

 

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Calling invalidate to repaint screen gives an error inside of a TimerTask instance.

 

Hi @mrdialect2012

 

Did you get any error?

 

E.

Contributor
Posts: 27
Registered: ‎05-10-2012
My Device: bold 9700
My Carrier: Vodafone

Re: Calling invalidate to repaint screen gives an error inside of a TimerTask instance.

Invalidstateerror

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Calling invalidate to repaint screen gives an error inside of a TimerTask instance.

I'm guessing that was from the updateDisplay() and not from the invalidate().  Can you tell us which instruction in your program caused this.  And also what is the detail message associated with the Exception. 

 

Remember you only call invalidate() when you want the screen to be repainted.  If you change something on the screen, like add a new Field, then that process will typically invalidate() the screen for you.

 

In addition, since the TimerTask does not run on the Event Thread, if you want to play with what is actually on display, then you need use some mechanism to get onto the Event Thread or get the Event lock, i.e. invokeLater, invokeAndWait or synchronizing on the Application event Lock.