MIDlet中显示图片问题???
我的代码如下:为什么最后图片没有显示到SCREEN上,请大家看看~~谢谢
我自己以为是:image = Image.createImage( "logo.png ");
中 "logo.png "图片路径引用错误,但是又不知道怎么改!!
图片放在; 工程/res目录下
package image;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImmutableImage extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command exit;
private Image image;
private ImageItem imageItem;
public ImmutableImage(){
display = Display.getDisplay(this);
form = new Form( "IMAGE ");
exit = new Command( "exit ",Command.EXIT,1);
form.addCommand(exit);
form.setCommandListener(this);
try{
System.out.println( "begin ");
image = Image.createImage( "logo.png ");
//image = Image.createImage( "res/logo.png ");
imageItem = new ImageItem( "java ",image,ImageItem.LAYOUT_LEFT, "My image ");
form.append(imageItem);
}
catch(
java.io.IOException error){
Alert alert = new Alert( "Error ", "Connt load myImage.png ",null,null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
public void startApp(){
display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command command,Displayable displayable){
if(command == exit){
destroyApp(false);
notifyDestroyed();
}
}
}
------解决方案--------------------image = Image.createImage( "/logo.png ");
试试?
------解决方案--------------------image = Image.createImage( "/logo.png ");
这个应该行的
------解决方案--------------------在Eclipse中和jar文件要在一个目录下