当前位置: 技术问答>java相关
这个异常为什么会出现,具体见内容。请帮忙
来源: 互联网 发布时间:2015-04-08
本文导语: 自定以一个JDialog class setDialog extends JDialog{ //func setDialog public setDialog(Frame own, String title, boolean modal){ //super(own,title,modal); System.out.println("constructor"); setSize(300,300); setBackground(Color.green); dgCon =this.getCo...
自定以一个JDialog
class setDialog extends JDialog{
//func setDialog
public setDialog(Frame own, String title, boolean modal){
//super(own,title,modal);
System.out.println("constructor");
setSize(300,300);
setBackground(Color.green);
dgCon =this.getContentPane();
}
//func dialogInit
protected void dialogInit(){
System.out.println("dialog");
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
stDg.dispose();}});
}
//var
Container dgCon;
}
在 chatSer dg = new chatSer(null,"dialog",true);
dg.dgCon = da.getContentPane();
执行后出现空指针异常,为什么
Exception in thread "main" java.lang.NullPointerException
at javax.swing.JDialog.getContentPane(JDialog.java:510)
at chatSer$setDialog.(chatSer.java:89)
at chatSer.(chatSer.java:27)
at chatSer.main(chatSer.java:44)
class setDialog extends JDialog{
//func setDialog
public setDialog(Frame own, String title, boolean modal){
//super(own,title,modal);
System.out.println("constructor");
setSize(300,300);
setBackground(Color.green);
dgCon =this.getContentPane();
}
//func dialogInit
protected void dialogInit(){
System.out.println("dialog");
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
stDg.dispose();}});
}
//var
Container dgCon;
}
在 chatSer dg = new chatSer(null,"dialog",true);
dg.dgCon = da.getContentPane();
执行后出现空指针异常,为什么
Exception in thread "main" java.lang.NullPointerException
at javax.swing.JDialog.getContentPane(JDialog.java:510)
at chatSer$setDialog.(chatSer.java:89)
at chatSer.(chatSer.java:27)
at chatSer.main(chatSer.java:44)
|
重载 dialoginit