bah - Strike one up for Nokia - again.
Device bug it would seem. This simple test sometimes fails after typing some input.
package dk.certus;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
/**
* @author Brian Matzon <matzon@certus.dk>
*/
public class TT extends MIDlet implements CommandListener {
private Form form;
private TextBox textBox;
private Command sendCommand;
private Command cancelCommand;
/**
* Creates a new MIDletLauncher
*/
public TT() {
super();
}
/**
* Proxies the call to the SystemController
*
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
form = new Form("Empty");
form.addCommand(new Command("Action", Command.SCREEN, 1));
form.setCommandListener(
new CommandListener() {
public void commandAction(Command c, Displayable d) {
showTextBox();
}
});
Display.getDisplay(this).setCurrent(form);
}
/**
* Proxies the call to the SystemController
*
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp() {
}
/**
* Proxies the call to the SystemController
*
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
}
private void showTextBox() {
sendCommand = new Command("Send", Command.OK, 1);
cancelCommand = new Command("Cancel", Command.CANCEL, 2);
textBox = new TextBox("To", null, 350, TextField.ANY);
textBox.addCommand(sendCommand);
textBox.addCommand(cancelCommand);
textBox.setCommandListener(this);
Display.getDisplay(this).setCurrent(textBox);
}
public void commandAction(Command command, Displayable displayable) {
String message;
// if send action, craft a message for symfoni
if(command == sendCommand && textBox.getString().length() > 0) {
message = textBox.getString();
} else {
char[] chars = new char[256];
textBox.getChars(chars);
message = "Error\n";
message += "Type: " + command.getCommandType();
message += "Label: " + command.getLabel();
message += "String: " + textBox.getString();
message += "Length: " + textBox.getString().length();
message += "Chars: " + new String(chars);
message += "Size: " + textBox.size();
message += "CaretPosition: " + textBox.getCaretPosition();
}
// yes create a new one each time - the error occurs regardless
textBox = null;
sendCommand = null;
cancelCommand = null;
Alert alert = new Alert("Result", message, null, null);
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(alert, form);
}
}