求解 为什么会发生Error occurred while dispatching event错误

wenjiguo 2008-02-21 12:13:25
一段source,在MOTO的模拟器上,点确认后发生下面error,在wireless的模拟器上和NOKIA 3110c的机器上没问题,求解
把itemProvince.setDefaultCommand(provinceCommand);注释掉就没问题 可是需要用这句呀


Error occurred while dispatching event:
java.lang.ArrayIndexOutOfBoundsException: No such child: 0
at java.awt.Container.getComponent(Unknown Source)
at com.motorola.moja.emulator.display.P2KSoftButtonStrategy.highLightMenuItem(Unknown Source)
at com.motorola.moja.emulator.display.P2KSoftButtonStrategy.drawMenu(Unknown Source)
at com.motorola.moja.emulator.display.Display.drawMenu(Unknown Source)
at com.sun.midp.lcdui.DefaultEventHandler.paintMenu(Unknown Source)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(Unknown Source)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

source:
/*
* UserInfomation.java
*
* Created on 2008年2月18日, 上午10:15
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package meetube.gui;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;

/**
*
* @author Administrator
*/
public class UserInfomation implements CommandListener,ItemCommandListener,ItemStateListener{

protected Form userInfomationForm;

private List listProvince;//省
private List listCity;//市

private ChoiceGroup provinceGroup;
private ChoiceGroup cityGroup;
private ChoiceGroup accessGroup;

private StringItem itemProvince;

private Command okCommand;
private Command exitCommand;
private Command provinceCommand;


private String[][] strs={
{"辽宁","沈阳"},
{"辽宁","大连"},
{"辽宁","鞍山"},
{"辽宁","抚顺"},
{"辽宁","本溪"},
{"辽宁","丹东"},
{"辽宁","锦州"},
{"辽宁","营口"},
{"辽宁","阜新"},
{"辽宁","辽阳"},
{"辽宁","铁岭"},
{"辽宁","朝阳"},
{"辽宁","盘锦"},
{"辽宁","葫芦岛"},
{"吉林","长春"}
};

private MainCanvas mainCanvas;

/**
* Creates a new instance of UserInfomation
*/
public UserInfomation(){

userInfomationForm=new Form("用户信息输入");

okCommand=new Command("确认",Command.OK,0);
exitCommand=new Command("退出",Command.EXIT,0);
provinceCommand=new Command("provinceCommand",Command.ITEM,1);

listProvince=new List("用户所在省选择",List.IMPLICIT);
listProvince.append(strs[0][0],null);
for(int i=1;i<strs.length;i++){
if(!strs[i][0].equals(strs[i-1][0])){
listProvince.append(strs[i][0],null);
}
}

cityGroup=new ChoiceGroup("用户所在市:",ChoiceGroup.POPUP);



accessGroup=new ChoiceGroup("GPRS接入方式:",ChoiceGroup.POPUP);
accessGroup.append("CMNET接入",null);
accessGroup.append("CNWAP接入",null);

itemProvince=new StringItem("用户所在省: ",null,StringItem.PLAIN);
itemProvince.setDefaultCommand(provinceCommand);
itemProvince.setItemCommandListener(this);
userInfomationForm.append(itemProvince);

userInfomationForm.append(cityGroup);
userInfomationForm.append(accessGroup);

userInfomationForm.addCommand(okCommand);
userInfomationForm.addCommand(exitCommand);

userInfomationForm.setCommandListener(this);
listProvince.setCommandListener(this);


}

public void commandAction(Command cmd, Displayable displayable) {

if(cmd==okCommand){

userInfomationForm.removeCommand(okCommand);
userInfomationForm.removeCommand(exitCommand);
itemProvince.removeCommand(provinceCommand);
mainCanvas=new MainCanvas();
GuiPublic.meetubeMain.display.setCurrent(mainCanvas);

}
else if(cmd==exitCommand){

userInfomationForm.removeCommand(okCommand);
userInfomationForm.removeCommand(exitCommand);
GuiPublic.meetubeMain.exit();

}else if(displayable.equals(listProvince)&&cmd==List.SELECT_COMMAND){
itemProvince.setText(listProvince.getString(listProvince.getSelectedIndex()));

cityGroup.deleteAll();
for(int i=0;i<strs.length;i++){
if(strs[i][0].equals(listProvince.getString(listProvince.getSelectedIndex()))){
cityGroup.append(strs[i][1],null);
}
}

GuiPublic.meetubeMain.display.setCurrent(userInfomationForm);
}

}

public void commandAction(Command cmd,Item item){

if(cmd==provinceCommand&&item==itemProvince){

GuiPublic.meetubeMain.display.setCurrent(listProvince);
}
}

public void itemStateChanged(Item item){
cityGroup.deleteAll();
if(item==provinceGroup){
for(int i=0;i<strs.length;i++){
if(strs[i][0].equals(provinceGroup.getString(provinceGroup.getSelectedIndex()))){
cityGroup.append(strs[i][1],null);
}
}
}

}
}
...全文
264 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧