I meet with this exception today:
java.lang.StringIndexOutOfBoundsException:
String index out of range: 8
at java.lang.String.substring(+29)
at chatmidlet.frmLogin.CommandPerformed(+166)
at chatmidlet.frmLogin$1.commandAction(+9)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+152)
at com.sun.kvem.midp.lcdui.EmulEventHandler$EventLoop.run(+427)
*************
my code respectively is:
public void CommandPerformed (Command c, Displayable d) {
if (c.getLabel() == "Login") {
try {
String Server = txtServer.getString() + ":" + txtPort.getString();
thisMIDlet.connect(Server);
thisMIDlet.send(new String ("login: " + txtNick.getString()));
String answer = new String(thisMIDlet.read());
if (answer.substring(0,8).compareTo("login ok") == 0) {
//get answer from Server,goto another Form
//Nickname and Server im MIDlet store
thisMIDlet.setServer(Server);
thisMIDlet.setNickname(txtNick.getString());
Display.getDisplay(thisMIDlet).setCurrent(thisMIDlet.getContent());
}
else {
//server sends error message back, 5 seconds
Alert alrtError = new Alert ("Error", answer.substring(0), null, AlertType.ERROR);
alrtError.setTimeout(5000);
Display.getDisplay(thisMIDlet).setCurrent(alrtError, this);
}//endif
thisMIDlet.disconnect();
}
catch (IOException e) {
// server not available
Alert alrtError = new Alert ("Error", "No Server available", null, AlertType.ERROR);
alrtError.setTimeout(5000);
Display.getDisplay(thisMIDlet).setCurrent(alrtError, this);
}
}
}
**********
the strange thing is this exception appears only recently after many times
test,even when I shut down the server and expect to get the "No Server available" error message.
I use JBuilder 5 to compile and run this MIDLet.
Thanks very much for your adivce.
[ January 09, 2003: Message edited by: Annina WG ]