Java me 在我添加复选框';s指数

Java me 在我添加复选框';s指数,java-me,Java Me,为什么在添加复选框的索引后程序无法运行。 agreeIndex=mainForm.append(同意) import javax.microedition.midlet.*; import java.util.*; import javax.microedition.lcdui.*; public class MainPage extends MIDlet implements CommandListener, ItemStateListener{ Ticker header; Display

为什么在添加复选框的索引后程序无法运行。 agreeIndex=mainForm.append(同意)

import javax.microedition.midlet.*;
import java.util.*;
import javax.microedition.lcdui.*;
public class MainPage extends MIDlet implements CommandListener, ItemStateListener{
Ticker header;
Display display;
Form mainForm;
TextField name, num, phone, email, age;
ChoiceGroup gender;
private int choiceGroupIndex;
Command nextCom, clearCom, exitCom;
Page1 p1;
ChoiceGroup agree = new ChoiceGroup("Please read the terms and conditions from menu."
        , Choice.MULTIPLE);
int agreeIndex;

public MainPage(){
    header = new Ticker("**ABC Restraurant**Customer Survey**");
    mainForm = new Form("Personal Information");
    name = new TextField("User name: ", "", 20, TextField.ANY);
    num = new TextField("User id: ", "", 10, TextField.NUMERIC);
    phone = new TextField("Phone no.: ", "", 10, TextField.PHONENUMBER);
    email = new TextField("E-mail: ", "", 20, TextField.ANY);
    age = new TextField("Age: ", "", 3, TextField.NUMERIC);
    gender = new ChoiceGroup("Gender: ", Choice.EXCLUSIVE);
    nextCom = new Command("Next", Command.SCREEN, 1);
    clearCom = new Command("Clear", Command.SCREEN, 2);
    exitCom = new Command("Exit", Command.EXIT, 3);
    p1 = new Page1(this);


    mainForm.setTicker(header);
    mainForm.append(name);
    mainForm.append(num);
    gender.append("Male", null);
    gender.append("Female", null);
    choiceGroupIndex = mainForm.append(gender);
    mainForm.append(age);
    mainForm.append(phone);
    mainForm.append(email);

    //agree.append("I agree with the terms and conditions.", null);
    mainForm.append(agree);

    mainForm.addCommand(nextCom);
    mainForm.addCommand(clearCom);
    mainForm.addCommand(exitCom);
    mainForm.setCommandListener(this);

}

public void commandAction(Command c, Displayable s) {
    if (c == exitCom)
    {
      try {
        destroyApp(false);
    } catch (MIDletStateChangeException e) {
        e.printStackTrace();
    }
      notifyDestroyed();
    } else if (c == clearCom) {
        resetTransferInformation();
    } else if (c == nextCom) {

        display.setCurrent(p1.list);
        //System.out.print(agreeIndex);
    }

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {


}

protected void startApp() throws MIDletStateChangeException {
    display = Display.getDisplay(this);
    display.setCurrent(mainForm);
    agree.append("I agree with the terms and conditions.", null);
    agreeIndex = mainForm.append(agree);

}

public void itemStateChanged(Item item)              
  {
  }

public void resetTransferInformation() {
    name.setString("");
    num.setString("");
    phone.setString("");
    email.setString("");
    age.setString("");
}

public void back() {
    display.setCurrent(mainForm);
}

}

您尝试将agree附加到mainForm两次。(在建造商和startApp中)


不正确

模拟器无法正常运行,它会立即运行并关闭。