03-02-2010 06:21 PM
I was following the code sample here and playing around with it. I received a RuntimeException when I changed the constructor for PleaseWaitDemoScreen a bit, and have no idea why.
The _waitScreen.show() method works perfectly fine inside the ButtonField's fieldChanged method. However, when I pulled it out of the button I got the RuntimeException (I pulled it out because I wanted the progress loading to start as soon as I push the PleaseWaitDemoScreen, and not after a button press). It seems that pushModalScreen() is breaking the code. I've tried app.invokeLater(new Runnable()) method and sychchronize with the eventlock, but the Exception is still there.
Any help would be appreciated. Thank you.
03-02-2010 08:07 PM
Can you tell us which exception is being thrown, and at what line of code (include a snippet)?
03-02-2010 08:21 PM - edited 03-02-2010 08:22 PM
Here's what I did.
I changed the constructor for PleaseWaitDemoScreen from:
public PleaseWaitDemoScreen() {
this.setTitle("PleaseWaitDemo");
ButtonField startButton = new ButtonField("Start", ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
startButton.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
_waitScreen = new PleaseWaitPopupScreen("Please wait", "Wating for test Thread", "dummy URL, not actually used");
int result = _waitScreen.show();
_resultField.setText("Result: " + Integer.toString(result));
}
});
this.add(startButton);
this.add(_resultField);
}To:
public PleaseWaitDemoScreen() {
this.setTitle("PleaseWaitDemo");
_waitScreen = new PleaseWaitPopupScreen("Please wait", "Wating for test Thread", "dummy URL, not actually used");
int result = _waitScreen.show();
_resultField.setText("Result: " + Integer.toString(result));
this.add(_resultField);
}
And the code throws a RuntimeException. The exact line of the exception is in PleaseWaitPopupScreen's show() method, on this line:
UiApplication.getUiApplication().pushModalScreen(this);
I tried the following fix for the above line:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushModalScreen(t his);
}
});
But the same RuntimeException persisted. Why would the same method work when called inside a ButtonField's fieldChanged method, but not when called directly from the current Screen?
Thanks for your fast reply.
03-02-2010 11:28 PM
Again, what is the exception? "Runtime exception" is meaningless. There are many.
It's hard to say looking at this one snippet, but I'm guessing that you have not yet entered the event dispatcher when this constructor is called. In this case, you would be getting some type of illegal state exception.
The reason it works in the listener is that the listener is only called as a result of some UI event, which means there is no way for it to be called until/unless the program is in the event dispatcher.