本帖最后由 张向辉 于 2013-2-4 21:42 编辑
package cn.itcast.day1;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
public class MyQQ {
/**
* @param args
*/
private Frame f;
private TextArea ta1,ta2;
private Button cancelBut,sendBut;
MyQQ()
{
init();
}
public void init()
{
f= new Frame("my qq");
ta1 = new TextArea(12,65);
ta2 = new TextArea(12,65);
Button cancelBut = new Button("取消");
Button sendBut = new Button("发送");
f.setBounds(200, 100, 500, 550);
f.setLayout(new FlowLayout());
f.add(ta1);
f.add(ta2);
f.add(cancelBut);
f.add(sendBut);
myEvent();
f.setVisible(true);
}
public void myEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
cancelBut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
f.setVisible(false);
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyQQ();
}
}
结果是:Exception in thread "main" java.lang.NullPointerException
at cn.itcast.day1.MyQQ.myEvent(MyQQ.java:54)
at cn.itcast.day1.MyQQ.init(MyQQ.java:40)
at cn.itcast.day1.MyQQ.<init>(MyQQ.java:22)
at cn.itcast.day1.MyQQ.main(MyQQ.java:63)
感觉代码正常,就是有异常,但是又不知道怎么解决
很烦躁
希望能给点这方面排场异常的经验
|
|