MyFirstMIDlet1.java
[code]
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MyFirstMIDlet1 extends MIDlet
{
private Display myDisplay;
public void MyFirstMIDlet1()
{
myDisplay = Display.getDisplay(this);
}
public void startApp()
{
Form myForm = new Form( "MyFirstMIDlet1 ");
myDisplay.setCurrent(myForm);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
}
[/code]
这个程序运行时有错“java.lang.NullPointerException”,而下面这个程序没有!
MyFirstMIDlet2.java
[code]
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MyFirstMIDlet2 extends MIDlet
{
public void MyFirstMIDlet2()
{
}
public void startApp()
{
Displayable current = Display.getDisplay(this).getCurrent();
if(current == null)
{
Form myForm = new Form( "MyFirstMIDlet ");
Display.getDisplay(this).setCurrent(myForm);
}
}
public void pauseApp(){}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
}
[/code]
有没有哪位好心人指点一下,谢谢!
------解决方案--------------------------------------------------------
MyFirstMIDlet1 extends MIDlet
{
private Display myDisplay;
public void MyFirstMIDlet1()
这里有个方法与类的名字一样,却不是构造函数?可以的吗?