java me - j2me sprite not working -
first, i'm sorry bad english. i'm newbie j2me
i wrote below code after watched tutorial not working. don't know happen it.
animationcanvas.java
package example; import java.io.ioexception; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.gamecanvas; import javax.microedition.lcdui.game.layermanager; import javax.microedition.lcdui.game.sprite; public class animationcanvas extends gamecanvas implements runnable { private sprite ca; private int framewidth = 14; private int frameheight = 14; private boolean playing = true; private int a=1; public animationcanvas(){ super(true); try { ca = new sprite(image.createimage("ca.png"), framewidth, frameheight); } catch (ioexception ex) { ex.printstacktrace(); } } public void start() { thread runner = new thread(this); runner.start(); } public void run(){ while (playing){ drawdisplay(getgraphics()); try{ thread.sleep(10); } catch(exception e){} } } public void drawdisplay(graphics g){ g.setcolor(0x000000); g.fillrect(0,0,getwidth(),getheight()); ca.setframe(1); ca.paint(g); flushgraphics(); } public void stop(){ playing=false; } }
and animationmidlet.java
package example; import java.io.ioexception; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class animationmidlet extends midlet { private display display; private animationcanvas canvas; public animationmidlet() throws ioexception { display = display.getdisplay(this); canvas = new animationcanvas(); } private void initialize() { // write pre-initialize user code here // write post-initialize user code here } public void startmidlet() { // write pre-action user code here // write post-action user code here } public void resumemidlet() { // write pre-action user code here // write post-action user code here } public void switchdisplayable(alert alert, displayable nextdisplayable) { // write pre-switch user code here display display = getdisplay(); if (alert == null) { display.setcurrent(nextdisplayable); } else { display.setcurrent(alert, nextdisplayable); } // write post-switch user code here } public display getdisplay() { return display.getdisplay(this); } public void startapp() { if(canvas!=null){ display.setcurrent(canvas); canvas.start(); } } public void pauseapp() { } public void destroyapp(boolean unconditional) { canvas.stop(); } }
and output
running in identified_third_party security domain java.io.ioexception uncaught exception java/lang/nullpointerexception. @ javax.microedition.lcdui.immutableimage.getimagefromstream(image.java:968) @ javax.microedition.lcdui.immutableimage.(image.java:939) @ javax.microedition.lcdui.image.createimage(image.java:313) @ example.animationcanvas.(animationcanvas.java:25) @ example.animationmidlet.(animationmidlet.java:25) @ java.lang.class.runcustomcode(+0) @ com.sun.midp.midlet.midletstate.createmidlet(+34)
thanks reading!
Comments
Post a Comment