BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 03-25-2009, 07:37 AM   #1
DD12
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
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, 08:03 AM   #2
SamuelD
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
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, 08:17 AM   #3
DD12
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
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, 09:40 AM   #4
zechariahs
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
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, 11:51 AM   #5
Ted Hopp
New Member
 
Join Date: May 2008
Model: none
PIN: N/A
Carrier: none
Posts: 4
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty picture

National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty

$690.00



Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON** picture

Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON**

$150.00



Hewlett Packard HP 70001A Mainframe Chassis Industrial Unit HP70000 System  picture

Hewlett Packard HP 70001A Mainframe Chassis Industrial Unit HP70000 System

$26.99



Agilent E1301B Mainframe  9-slots with multimeter, totalizer, and relay muxes picture

Agilent E1301B Mainframe 9-slots with multimeter, totalizer, and relay muxes

$200.00



NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME picture

NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME

$499.99



National Instruments NI PXI-1044 Chassis 14-Slot PXI Mainframe 189105E-01 Rev 01 picture

National Instruments NI PXI-1044 Chassis 14-Slot PXI Mainframe 189105E-01 Rev 01

$199.99







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