Exception in thread "main" java.lang.NullPointerException
林昭希 2011-10-16 03:11:58 package hanshunpingstudy;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class qqFace extends JFrame {
JFrame jFrame = null;
JPanel jPanel2 = null;
JComboBox jComboBox = null;
JButton jButton = null;
JScrollPane jScrollPane = null;
JTextField jTextField = null;
JTextArea jTextArea = null;
public qqFace() {
String chatter[] = { "nimam", "caocao", "daiding" };
// jFrame = new JFrame();
jPanel2 = new JPanel();
jTextArea = new JTextArea();
jScrollPane = new JScrollPane(jTextArea);
jComboBox = new JComboBox(chatter);
jTextField = new JTextField(10);
jButton = new JButton("发送");
// 添加组件
/**
* 关键是在这部分,那就是把什么组件加到什么组件里面,
* 要熟知什么是顶级容器,什么是一般容器
*/
// jFrame.add(jScrollPane);
// jPanel.add(jTextArea);
// jScrollPane.add(jPanel);
// jFrame.add(jPane2, BorderLayout.SOUTH);
jPanel2.add(jScrollPane);
jPanel2.add(jTextField);
jPanel2.add(jButton);
this.add(jTextArea);
this.add(jPanel2, BorderLayout.SOUTH);
/**
* this.add(jScrollPane); this.add(jPane2, BorderLayout.SOUTH);
* jPanel2.add(jComboBox, FlowLayout.LEFT); jPanel2.add(jTextField,
* FlowLayout.CENTER); jPanel2.add(jButton, FlowLayout.RIGHT);
*/
// 设置大小
jFrame.setSize(100, 250);
jFrame.setIconImage(new ImageIcon("images/qq.gif").getImage());
jFrame.setTitle("QQ2011");
jFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
jFrame.setVisible(true);
}
public static void main(String[] args) {
qqFace qqface = new qqFace();
}
}
Exception in thread "main" java.lang.NullPointerException
at hanshunpingstudy.qqFace.<init>(qqFace.java:52)
at hanshunpingstudy.qqFace.main(qqFace.java:61)
错误行我用红色标注出来了,我写了几个GUI界面,但是Exception in thread "main" java.lang.NullPointerException这个错误老是出现,很郁闷,我看的是那个韩顺平的视频,人家写的对的,但是我抄过来怎么是错的呢?
我该怎么避免呢?为什么有的代码中这样写是对的,而有的代码中这样写就是错的呢?
我就郁闷了,烦劳各位大神解析,感激不尽啊!
对了,我对组件之间的添加还不是很熟悉其中的规则,对于什么是顶级容器一般容器,一般组件添加规则,不太熟,烦劳了,望各位大神指点。