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

MIDlet报java.lang.NullPointerException异常!

2014-01-26 
MIDlet报java.lang.NullPointerException异常:MyFirstMIDlet1.java [code] import javax.microedition.midl

MIDlet报java.lang.NullPointerException异常:

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()
这里有个方法与类的名字一样,却不是构造函数?可以的吗?

        

热点排行