我写了以下内容Java Application
:
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
public class JavaApplication6 extends MIDlet
{
private static Form clockForm=null;
private static StringItem clockItem=new StringItem("hello", "World!");
private static ClockTask task=null;
private static Timer timer=null;
static class ClockTask extends TimerTask
{
private int count=0;
@Override
public void run()
{
count++;
clockItem.setText("hello "+count);
}
}
public static void JavaApplication6() throws Exception
{
clockForm=new Form("Clock");
clockItem=new StringItem("","0");
clockForm.append(clockItem);
}
@Override
public void startApp()
{
task=new ClockTask();
timer=new Timer();
timer.schedule(task,1000,1000);
Display.getDisplay(this).setCurrent(clockForm);}
@Override
public void pauseApp()
{}
public void destroyApp(boolean unconditional)
{}
public static void main(String[] args) {
JavaApplication6 test=new JavaApplication6();
test.startApp();
}
}
但是当我运行它时,它exception
在最后一行给了我以下内容startApp()
;
Exception in thread "main" java.lang.NullPointerException
at javax.microedition.lcdui.Display.<init>(Display.java:420)
at javax.microedition.lcdui.Display.getDisplay(Display.java:447)
at javaapplication6.JavaApplication6.startApp(JavaApplication6.java:42)
at javaapplication6.JavaApplication6.main(JavaApplication6.java:56)