站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2ME 专题有关List的一个简单问题!!!!

有关List的一个简单问题!!!!

摘要: 有关List的一个简单问题!!!!


下午按书写的,弄了一个小程序来学习List
但是,出现了一个错误,在类ListDemoextends下面有个错误提示:
The type ListDemoextends must implement the inherited abstract method CommandListener.
commandAction(Command, Displayable)
但是,我已经写了commandAction啊.求高人解答.非常感谢!
附原码:
import java.io.IOException;

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class ListDemoextends extends MIDlet implements CommandListener{

private final static Command CMD_EXIT = new Command("Exit",Command.EXIT,1);
private final static Command CMD_BACK = new Command("Back",Command.BACK,1);
private Display display;
private List mainList;
private List exclusiveList;
private List implicitList;
private List multipleList;

//private boolean firstTime;

public ListDemoextends() {
display = Display.getDisplay(this);

String[] stringArray = {"Option A","Option B","Option C","Option D"};
Image[] imageArray = null;

exclusiveList = new List("Exclusive",Choice.EXCLUSIVE,stringArray,imageArray);
exclusiveList.addCommand(CMD_BACK);
exclusiveList.addCommand(CMD_EXIT);
exclusiveList.setCommandListener(this);

implicitList = new List("Implicit",Choice.IMPLICIT,stringArray,imageArray);
implicitList.addCommand(CMD_BACK);
implicitList.addCommand(CMD_EXIT);
implicitList.setCommandListener(this);

multipleList = new List("Multiple",Choice.MULTIPLE,stringArray,imageArray);
multipleList.addCommand(CMD_BACK);
multipleList.addCommand(CMD_EXIT);
multipleList.setCommandListener(this);

//firstTime = true;
}

protected void startApp(){
Image[] imageArray = null;

try{
Image icon = Image.createImage("/png/SV-262e1.png");

imageArray = new Image[]{icon,icon,icon};
}catch(IOException err){
System.out.println("Erro in Loading!");
}

String[] stringArray = {"Exclusive","Implicit","Multiple"};

mainList = new List("Choose type",Choice.IMPLICIT,stringArray,imageArray);
mainList.addCommand(CMD_EXIT);
mainList.setCommandListener(this);
}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void destroyApp(boolean arg0){
// TODO Auto-generated method stub

}

protected void CommandAction(Command c, Displayable d){
if(d.equals(mainList)){
if(c == List.SELECT_COMMAND){
switch(((List)d).getSelectedIndex()){
case 0:
display.setCurrent(exclusiveList);
break;

case 1:
display.setCurrent(implicitList);
break;

case 2:
display.setCurrent(multipleList);
break;
}
}
}else{
if(c == CMD_BACK){
display.setCurrent(mainList);
}
}

if(c == CMD_EXIT){
destroyApp(false);
notifyDestroyed();
}
}

}


commandAction() 这个方法首字母是小写的。 仔细看看API


嘻嘻,是我大意了,不过,我将CommandAction改为commandAction后,原来的错误没有了,但,又出现在commandAction下出现在另一个错误:
Cannot reduce the visibility of the inherited method from CommandListener

再次求助!!!


public void commandAction() 前面是public的。试一下。


改为public,表面上没有错误了,但运行起来,非但没有能够达成希望的效果,反而提示:
Warning: Running JAM, Ignoring all other options (but "-Xheapsize", and OTA flags if provided)
正在通过存储根 DefaultColorPhone 来运行
** Error installing suite (39): The JAD matches a version of a suite already installed.
Execution completed.
247550 bytecodes executed
2 thread switches
738 classes in the system (including system classes)
1524 dynamic objects allocated (64160 bytes)
1 garbage collections (0 bytes collected)



是不是Image icon = Image.createImage("/png/SV-262e1.png");这句有问题啊,为什么将路径改为"Image icon = Image.createImage("/png/SV-262e1.png");"就会被划红波浪线,路径不是用"/"吗?我的SV-262e1.png文件,存在./png文件夹下,应该不会有错吧,请k7sem多多指教!非常感谢!


在startApp() 的最后加上 display.setCurrent(mainList);



我真的是太粗心了!
程序运行,抛出Erro in Loading!,是catch抛出的,说明载入PNG图片时错误.如果图片不是这么载入的,那么正确的载入方法应该是什么呢?


Image img;
try
{
img = Image.createImage("/img.png");
}catch(Exception e)
{
e.printStackTrace();
System.out.println("Load image error");
}


↑返回目录
前一篇: [菜鸟问题]各位高手帮我看下出现异常:java.lang.NullPointerException是怎么回事啊(JB中编译通过)
后一篇: 请教各位,在安装NOKIA7210开发环境的时候出现问题!