Reputation: 1905
I have a BlackBerry App that has a Listener for the Send Button implemented in the CheckIn
Screen. Data is sent through a web service. If the data is sent successfully, a confirmation message of "OK" is received. I am trying to switch screens in my BlackBerry App depending on the response received.
FieldChangeListener sendBtnListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
try {
String alertMsg=sendTextCheckIn();
if(alertMsg.equals("OK"))
{
UiApplication.getUiApplication().invokeLater( new Runnable()
{
public void run ()
{
UiApplication.getUiApplication().pushScreen(new MyScreen());
}
} );
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
However, the above is throwing an App Error 104: IllegalStateException
. Can anyone please guide on how to switch screens between a BlackBerry App.
EDIT: I can switch to any other screen but I CAN NOT switch to MyScreen
. NOTE:
MyScreen is the main (first) screen of the App. The above method sendTextCheckIn()
calls another method that is placed inside MyScreen
. Has this got anything to do with the error? Please advice.
Upvotes: 0
Views: 102
Reputation: 3915
Wrap everything that could possibly raise in exception in try/catch.
Don't do e.printStackTrace()
- that won't give you much.
Instead do something like System.err.println ("KABOOM in method abc() - " + e);
- seems like more effort, but trust me, that becomes INVALUABLE when debugging issues like this.
Catch Exception
, unless you have a VERY good reason to catch a specific a subtype - otherwise you WILL end up with unexpected, and uncaught exceptions, which you will hunt for DAYS.
Upvotes: 1
Reputation: 11876
The 'fieldChanged' event is already running on the UI event thread, so you shouldn't need to do the invokeLater call within it, just call pushScreen directly.
You mention that your problem with IllegalStateException only happens for MyScreen. That makes it sound like something specific with the implementation of MyScreen. Start narrowing down the problem - look at what happens in the constructor of MyScreen, and any events that might get called before the screen is visible. Some of that code is what is causing the problem.
Upvotes: 3