程序抛出
java.lang.NullPointerException 请教!!!
package newpackage;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author kl0
* @version
*/
public class MyCartoonMidlet extends MIDlet {
public MainCanvas m_MainCanvas;
public MyCartoonMidlet(){
super();
}
public void startApp() throws MIDletStateChangeException {
m_MainCanvas=new MainCanvas();
Display.getDisplay(this).setCurrent(m_MainCanvas);
while(true){
m_MainCanvas.repaint();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) throws MIDletStateChangeException{
}
}
package newpackage;
import
java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
*
* @author kl0
*/
public class MainCanvas extends Canvas{
public Image m_Image;
/** Creates a new instance of MainCarvas */
public MainCanvas() {
try {
m_Image=Image.createImage( "/IM.png ");
} catch (
IOException e) {
}
}
protected void paint(Graphics graphics) {
graphics.drawImage(m_Image,0,0,Graphics.TOP|Graphics.LEFT);
}
}
/*运行的时候就
java.lang.
NullPointerException:
at newpackage.MainCanvas.paint(MainCanvas.java:34)
at javax.microedition.lcdui.Canvas.callPaint(Canvas.java:1063)
at javax.microedition.lcdui.Display.repaint(Display.java:1435)
at javax.microedition.lcdui.Display$DisplayAccessor.repaint(Display.java:2165)