首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

点击’Details'报异常:java.lang.NullPointerException,JB2006下编译通过,但是NOKIA7210模拟器环境运行时出现’

2014-01-26 
JB2006下编译通过,但是NOKIA7210模拟器环境运行时出现&ldquoApplication Eorrer&rdquo,点击&ldquoDetai

 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         

热点排行