BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-25-2009, 08:37 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question JDE 4.7 -JDE 4.7 - java.lang.IIIegalStateException

Please Login to Remove!

Hello Everyone

I have following code:

import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.synchronization.*;
import net.rim.device.api.math.*;
import net.rim.device.api.system.*;
import net.rim.blackberry.api.phone.phonelogs.*;

class Phone_Call_Log extends UiApplication
{
MainScreen _screen = new MainScreen();
Phonethread _phone;
PhoneLogs _logs;

public static void main(String arg[])
{
Phone_Call_Log application = new Phone_Call_Log();
application.enterEventDispatcher();
}

public Phone_Call_Log()
{
_screen.setTitle("Phone Log";
_screen.add(new RichTextField("Activities on your Phone");
_screen.add(new SeparatorField());
pushScreen(_screen);
_phone = new Phonethread();
_phone.start();
}

private final class Phonethread extends Thread
{

public Phonethread()
{
super();
}

public void run()
{
_logs = PhoneLogs.getInstance();

for(int i=0;i< (_logs.numberOfCalls(_logs.FOLDER_NORMAL_CALLS));i ++)
{

PhoneCallLog callLog = (PhoneCallLog) _logs.callAt(i, _logs.FOLDER_NORMAL_CALLS);

String number=callLog.getParticipant().getNumber();

if(callLog.getType() == callLog.TYPE_RECEIVED_CALL)
{
_screen.add(new RichTextField ("You received a call from: " + number));
}

if(callLog.getType() == callLog.TYPE_PLACED_CALL)
{

_screen.add(new RichTextField ("The number you dialed was: ");
// _screen.add(new RichTextField ("it was made on: "+data));
}



}

}
}
}

---- End of Code ---

I receive java.lang.IIIlegalStateException error at line which is in bold.

Any Ideas why?

Thanks
Offline  
Old 03-25-2009, 09:03 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2009
Location: Quebec, Ca
Model: 8330
OS: v4.5.0.77
PIN: 30293EF0
Carrier: Telus
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,
I don't see the line in bold, but I think your problem is near there :
_screen.add(new RichTextField ("You received a call from: " + number));

To modify a screen from a thread, you need to be synchronized with the Event lock. Try this before the line :
synchronized (Application.getEventLock()) {
Offline  
Old 03-25-2009, 09:17 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about that. Yes that is the line I get error on.

I will try that.

Found this too.

Livelink - Redirection


Thanks.
Offline  
Old 03-25-2009, 10:40 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

To generalize a bit more, anytime you're updating the UI you want to make sure you have the event lock.

Like SamuelD mentioned, use the following code:

Code:
synchronized (Application.getEventLock()) 
{
   // Update UI here
}
__________________
Handspring >> Palm >> BB Pearl >> BB Storm

Tumblog: http://www.geekkink.com
Blog: http://www.zechariahs.org/blog
Offline  
Old 03-25-2009, 12:51 PM   #5 (permalink)
New Member
 
Join Date: May 2008
Model: none
PIN: N/A
Carrier: none
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alternatively, you can use
Code:
Application.getApplication().invokeLater(new Runnable() {
  public void run() {
    // Update UI here
  }
});
(or use invokeAndWait() if necessary). The Runnable can also be kept in a variable and reused.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.