JB2006下编译通过,但是NOKIA7210模拟器环境运行时出现“Application Eorrer”,点击“Details”出现异常报告:java.lang.NullPointerException
代码如下:
ok3.java
package ok3;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ok3 extends MIDlet {
private Canvas canvas;
private Display display;
static ok3 instance;
ok3Displayable displayable = new ok3Displayable();
public ok3() {
instance = this;
}
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
canvas = new ok3Displayable();
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean bool) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
==================
ok3Displayable
==================
package ok3;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import java.io.*;
public class ok3Displayable extends Canvas implements CommandListener {
public ok3Displayable() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
setCommandListener(this);
addCommand(new Command("Exit", Command.EXIT, 1));
}
public void commandAction(Command command, Displayable displayable) {
if (command.getCommandType() == Command.EXIT) {
ok3.quitApp();
}
}
private Image kk = null;
public void ok3Displayable(){
try {
kk = Image.createImage("/ohyeah.png");
}
catch(IOException e) {
e.printStackTrace();
}
}
protected void paint(Graphics g) {
g.setColor(221, 71, 71); // red