Your main fault here is I think not using appropriate logging in your MIDlet. Other than that, there are no evident mistakes in the code snippet you posted.
It is most likely that the error is caused by something going wrong in your getForm()
method code, but since there is no logging, you have to also check other possibilities like eg that command listener or no
command object, or alert
object has been somehow changed somewhere else in your code.
With logging like shown in example below, you could simply run your midlet in emulator and check console messages to find out whether expected code has been executed or not:
public void commandAction(Command command, Displayable displayable) {
Log.log("command: [" + command.getCommandLabel()
+ "] at screen: [" + displayable.getTitle() + "]");
if(displayable==textbox)
{
Log.log("in textbox");
if(command==exit)
{
Log.log("handle exit command");
switchDisplayable(null,alert);
}
}
else if(displayable==alert)
{
Log.log("in alert");
if(command==no)
{
Log.log("handle no command");
switchDisplayable(alert,getForm());
}
else if(command==yes)
{
Log.log("handle yes command");
switchDisplayable(alert,getTextbox());
}
}
}
//...
public class Log {
// utility class to keep logging code in one place
public static void log (String message) {
System.out.println(message);
// when debugging at real device, S.o.p above can be refactored
// - based on ideas like one used here (with Form.append):
// http://stackoverflow.com/questions/10649974
// - Another option would be to write log to RMS
// and use dedicated MIDlet to read it from there
// - If MIDlet has network connection, an option is
// to pass log messages over the network. Etc etc...
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…