当前位置: 代码迷 >> J2ME >> 这段代码是如何了,编译没有异常
  详细解决方案

这段代码是如何了,编译没有异常

热度:6764   发布时间:2013-02-25 21:38:14.0
这段代码是怎么了,编译没有错误啊
我的这段代码不知道怎么了,编译没有错误但是却不能正确运行
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/*游戏Canvasc测试*/
public class gamecanvas extends MIDlet {

private Display dis;
private MyGameCanvas mgc=new MyGameCanvas();
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
dis.setCurrent(mgc);


}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {


}

protected void pauseApp() {


}
//创建我的游戏画布
class MyGameCanvas extends GameCanvas implements Runnable{
private Image img;
private Graphics gr;
private Sprite sp;
protected MyGameCanvas() {
super(true);
gr=this.getGraphics();
try{
img=Image.createImage("4.png");
}catch(Exception ex)
{
ex.printStackTrace();
}
sp=new Sprite(img);
sp.paint(gr);
new Thread(this).start();
}
public void run()
{
while(true)
{
try{

}catch(Exception ex)
{
ex.printStackTrace();
}
}

}
}


}


------解决方案--------------------------------------------------------
Java code
img=Image.createImage("4.png");
  相关解决方案