java.lang.ArrayIndexOutOfBoundsException

John McCosker <[email protected]> Thu, 11 Nov 2004 11:04:28 -0700
Newsgroups gmane.comp.java.sun.cldc
Message-ID <LISTSERV%[email protected]>
Hi,

I am a total j2me newbie so forgive me,

I am getting this error when I try to run a Midlet with j2me wireless
toolkit emulator,


C:\WTK104\bin>emulator -Xdescriptor:C:\midlets\classes\LoginMidlet.jad
java.lang.ArrayIndexOutOfBoundsException
at com.sun.midp.midlet.Selector.commandAction(+36)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+152)
at com.sun.kvem.midp.lcdui.EmulEventHandler$EventLoop.run(+459)

the phone loads in the emulator, but whan I click the soft button for
launch it throughs the ArrayIndexOutOfBoundsException. I thought this may
have something to do with the size of
the jar file and its referenced size in the jad file, but it is the exact
size of LoginMidlet.jar file.
I have included the class and jad file below. Its very simple, there is
only one class within my jar.

Could this possibly be a jvm exception as oppossed to a runtime.

I am using j2sdk1.4.2_06 and j2me_wireless_toolkit-1_0_4_02 for windows.

the midlet is very simple,


import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public
class LoginMidlet extends MIDlet implements CommandListener{
 private Display display; private TextField username;
 private TextField password; private Form form; private
Command cancel; private Command login;  public LoginMidlet(){
 username = new TextField("LoginID:","",10,TextField.ANY);
 password = new TextField("Password:","",10,TextField.PASSWORD);
 form = new Form("Sign In");  cancel = new Command
("Cancel",Command.CANCEL,2);  login = new Command
("Login",Command.OK,2); }  public void startApp(){
 display = Display.getDisplay(this);  form.append
(username);  form.append(password);  form.addCommand
(cancel);  form.addCommand(login);
 form.setCommandListener(this);  display.setCurrent(form);
 }  public void pauseApp(){}  public void
destroyApp(boolean unconditional){  notifyDestroyed(); }
  public void validateUser(String name,String password){
 if(name.equals("qm")&&password.equals("j2")){   menu
();  }else{   tryAgain();  } }
  public void menu(){  List services = new List
("Choose one",Choice.EXCLUSIVE);  services.append("Check
Mail",null);  services.append("Compose",null);
 services.append("Addresses",null);  services.append
("Options",null);  services.append("Sign Out",null);
 display.setCurrent(services); }  public void tryAgain
(){  Alert error = new Alert("Login Incorrect","Please try
again",null,AlertType.ERROR);  error.setTimeout(Alert.FOREVER);
  username.setString("");  password.setString("");
 display.setCurrent(error,form); }  public void
commandAction(Command c,Displayable d){  String label = c.getLabel();
  if(label.equals("Cancel")){   destroyApp
(true);  }else if(label.equals("Login")){
 validateUser(username.getString(),password.getString());
 } } }


this is my jad file,

MIDlet-: Login,,LoginMidlet
MIDlet-Name: LoginMidlet
MIDlet-Version: 1.0
MIDlet-Vendor: ORA
MIDlet-Jar-URL: LoginMidlet.jar
MIDlet-Jar-Size: 2169

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff CLDC-FEEDBACK".  For general help, send email to
[email protected] and include in the body of the message "help".