eclipse+wtk,图片显示问题,不能显示

来源:百度知道 编辑:UC知道 时间:2024/07/07 16:50:31
代码如下:
import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ImageMidlet extends MIDlet implements CommandListener {
private Image img=null;
private Display display=null;
private List form=new List("图片",List.IMPLICIT);
private Command exitCommand=new Command("退出",Command.EXIT,1);
private Command backCommand=new Command("后退",Command.BACK,1);
public ImageMidlet(){
if(display==null){
display=Display.getDisplay(this);
try {
img=Image.createImage("2.png");
} catch (IO

img=Image.createImage("2.png");
改成:
img=Image.createImage("/2.png");
图片放在src目录下

add://

别的地方没有错误,我也试了,把它改了之后可以正常显示,如果你的不能够显示的话,估计是png格式有问题,你可以用wtk目录下的一个png来试试
还有,如果是moto的模拟器的话似乎要是24位或以下,而不是32位,如果还有问题你再找我吧