j2me: IllegalStateException - Anfänger braucht Hilfe

MaRiBo

Grünschnabel
Hallo,
habe ein kleines Programm, welches ich auf mein Siemens C60 überspielen möchte. Bekomme beim Versuch es auszuführen Fehlermeldung:

Exception in MIDlet.startApp()java.lang IllegalStateException: Alert does not accept commands

Finde den Fehler nicht:


package calculator;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public final class CalculatorMIDlet extends MIDlet implements CommandListener {


private static final int NUM_SIZE=15;

private final Command exitCmd = new Command("Exit", Command.EXIT, 2);

private final Command calcCmd = new Command("Calc", Command.SCREEN, 1);

private final TextField t1 = new TextField("K ", "", NUM_SIZE,
TextField.NUMERIC);

private final TextField t2 = new TextField("F ", "", NUM_SIZE,
TextField.NUMERIC);
private final TextField t3 = new TextField("M ", "", NUM_SIZE,
TextField.NUMERIC);

private final TextField tr = new TextField("Z ", "", NUM_SIZE,
TextField.UNEDITABLE);

private final Alert alert = new Alert("", "", null, AlertType.INFO);

private boolean isInitialized = false;


protected void startApp() {
if (isInitialized) {
return;
}

Form f = new Form("Points");

f.append(t1);
f.append(t2);
f.append(t3);
f.append(tr);

f.addCommand(exitCmd);
f.addCommand(calcCmd);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);

alert.addCommand(new Command("Back", Command.SCREEN, 1));
isInitialized = true;
}

protected void destroyApp(boolean unconditional) {}


protected void pauseApp() {}


public void commandAction(Command c, Displayable d) {
if (c == exitCmd) {
destroyApp(false);
notifyDestroyed();
return;
}
int res = 0;

try {
int n1 = getNumber(t1, "First");
int n2 = getNumber(t2, "Second");
int n3 = getNumber(t3, "Third");

{
res = (n1/60 + n2/9) * n3/100;

}
} catch (NumberFormatException ex) {
return;
} catch (ArithmeticException ex) {
alert.setString("Divide by zero.");
Display.getDisplay(this).setCurrent(alert);
return;
}

String res_str = Integer.toString(res);

if (res_str.length() > tr.getMaxSize()) {
tr.setMaxSize(res_str.length());
}
tr.setString(res_str);
}
private int getNumber(TextField t, String type)
throws NumberFormatException {
String s = t.getString();

if (s.length() == 0) {
alert.setString("No Argument");
Display.getDisplay(this).setCurrent(alert);
throw new NumberFormatException();
}
int n;

try {
n = Integer.parseInt(s);
} catch (NumberFormatException e)


{
alert.setString(" argument is out of range.");
Display.getDisplay(this).setCurrent(alert);
throw e;
}
return n;
}
}

Bin für jede Hilfe dankbar
Gruß MaRiBo
 
Zurück