【J2ME】无法加载图片 Image cannot be loaded or decoded!(100分)

  • 主题发起人 主题发起人 ZRWeng
  • 开始时间 开始时间
Z

ZRWeng

Unregistered / Unconfirmed
GUEST, unregistred user!
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
public ImageCanvas extends Canvas{
public ImageCanvas() {
}
public void paint(Graphics g){
try
{
Image img=Image.createImage("/2.png");
g.drawImage(img,0,0,g.TOP|g.LEFT);
}
catch(IOException e)
{
System.out.println(e);
}
}
}
////////////////////////////Main Class//////////////////////////////
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageEx extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private ImageCanvas canvas;
public ImageEx() {
exitCommand = new Command("退出", Command.EXIT, 1);
canvas = new ImageCanvas();
display = Display.getDisplay(this);
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
public void startApp() {
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
display.setCurrent(canvas);
}
public void pauseApp() {}
public void destroyApp(boolean b) {}
}
错误提示:Image cannot be loaded or decoded
将2.png放置在resources,src目录都没有用!
环境jb9+MobileSet3 模拟器motorola T720
搞了很久还是没搞定 :(!!
 
你试试将图片打包进jar文件看看行不行,我自己用jbuilder7.0,好像也不能正确显示图片,不过用Nokia Developer's Suite for J2ME将其打包就能正确显示了。
 
换了Nokia模拟器可以显示图片了,应该是motorola模拟器问题吧
 
接受答案了.
 
后退
顶部