super.close giving illegalstateexception
Please Login to Remove!
okay, this is my first time ever posting, i am writing my first blackberry app. Trying to open a screen that starts a timer and when timer finishes, it closes but i keep getting an illegalstateexception error. Here is the code:
Call to open window (from another window):
TimerScreen ts = new TimerScreen(5);
UiApplication.getUiApplication().pushScreen(ts);
I commented out all my timer stuff since i thought that might be the problem, here is what is left (but i still get the error): RED LINE IS THE PROBLEM
public class TimerScreen extends MainScreen {
private int statusValue = 0;
private Timer timer;
private Vector fields = new Vector();
private TimerTask tt;
public void close() {
System.out.println("junk");
// try {
// timer.cancel();
// }
// catch (Exception e) {}
super.close();
System.out.println("just before pop");
Screen screen=UiApplication.getUiApplication().getActiveS creen();
if (screen instanceof TimerScreen) {
UiApplication.getUiApplication().popScreen(screen) ;
} else
add(new LabelField("junkk"));
}
public boolean isDirty() {
return false;
}
public TimerScreen(int NumOfSeconds) {
// get the MainScreen's VerticalFieldManager...
super();
Manager vfm = this.getMainManager();
timer = new Timer();
//default gauge
final GaugeField gf1;
{
gf1 = new GaugeField("Custom gauge",
0, 100, 0,
GaugeField.NO_TEXT | GaugeField.PERCENT | GaugeField.LABEL_AS_PROGRESS);
// gf1.setLabel("default gauge:");
// gf1.setValue(12);
fields.addElement(gf1);
}
// custom gauge
final GaugeField gf2;
{
gf2 = new GaugeField("custom gauge:",
0, 100, 0,
GaugeField.NO_TEXT | GaugeField.PERCENT | GaugeField.LABEL_AS_PROGRESS);
fields.addElement(gf2);
}
// custom gauge #2
final GaugeField gf3;
{
gf3 = new GaugeField("Picture will display in:",
0, 100, 0,
GaugeField.PERCENT | GaugeField.LABEL_AS_PROGRESS);
fields.addElement(gf3);
}
// custom gauge #3
final GaugeField gf4;
{
gf4 = new GaugeField("At 100% next picture will appear",
0, 100, 0,
GaugeField.LABEL_AS_PROGRESS);
fields.addElement(gf4);
}
// add all the fields to the vfm...
{
// add all the guagefields
for (int i = 0; i < fields.size(); i++) {
Object field = fields.elementAt(i);
vfm.add((Field) field);
}
// add a separator
vfm.add(new SeparatorField(SeparatorField.LINE_HORIZONTAL));
}
System.out.println(":: TimerDemo adding components to the MainScreen...");
/*
tt=new TimerTask() {
public void run() {
if (statusValue >= 100) {
try {
tt.cancel();
timer.cancel();
}
catch (Exception e) {}
System.out.println(
":: TimerDemo shutting down timer (and subsequent timer tasks)... statusValue > 100");
close();
}
else {
statusValue=statusValue+20;
for (int i = 0; i < fields.size(); i++) {
Object field = fields.elementAt(i);
((GaugeField) field).setValue(statusValue);
}
System.out.println(
":: TimerDemo firing a status value update... statusValue=" + statusValue);
}
}
};
*/
// timer.schedule(tt,0,1000);
invalidate();
System.out.println(":: TimerDemo starting timer task...");
close();
}
}// end MainScreen
|