我的这段代码不知道怎么了,编译没有错误但是却不能正确运行
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");