OptionsScreen.java
private final MainMidlet midlet;
OptionsScreen(MainMidlet midlet)
{
super("游戏参数设定");
this.midlet = midlet;
choicelevel = new ChoiceGroup("选择游戏难度:", 1);
choicelevel.append("难", null);
choicelevel.append("易", null);
append(choicelevel);
choiceBackground = new ChoiceGroup("选择背景风格:", 1);
choiceBackground.append("炫彩舞台", null);
choiceBackground.append("风车", null);
choiceBackground.append("炫蓝", null);
choiceBackground.append("瀑布", null);
choiceBackground.append("竹排", null);
append(choiceBackground);
choiceMusic = new ChoiceGroup("选择背景音乐:", 1);
choiceMusic.append("静音", null);
choiceMusic.append("春江花月夜", null);
choiceMusic.append("城里的月光", null);
choiceMusic.append("菊花台", null);
append(choiceMusic);
CMD_OK = new Command("确定", 4, 2);
addCommand(CMD_OK);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d)
{
if (c == CMD_OK)
{
level = (byte)choicelevel.getSelectedIndex();
back = (byte)choiceBackground.getSelectedIndex();
music = (byte)choiceMusic.getSelectedIndex();
midlet.optionsBack(level,back,input,music); //这句中有抛出错误
// java.lang.NullPointerException
}
这样一直抛出异常,不知道该怎么解决,希望得到大家的帮助,谢谢!!
java.lang.NullPointerException
at MainMidlet.optionsBack(+9)
at OptionsScreen.commandAction(+67)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
------解决方案--------------------------------------------------------
单步跟踪一下,看看 midlet 和传进去的参数是否为空
------解决方案--------------------------------------------------------
midlet定义为final,就是不可变的,只有在类加载或构造方法中可以初始化它
然后你在方法中对它赋值,所以出错
------解决方案--------------------------------------------------------
我是来拿分的
------解决方案--------------------------------------------------------
LZ看看这里 final的问题
------解决方案--------------------------------------------------------
我只能说空指针异常。。
------解决方案--------------------------------------------------------
你dubug进去 看看到底怎么回事
------解决方案--------------------------------------------------------
input,应该是这个参数的问题