出现空指针异常错误,找不到原因
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class Ftest extends JFrame
{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextArea jTextArea = null;
private JPanel controlPanel = null;
private JButton openButton = null;
private JButton closeButton = null;
private JButton getOpenButton()
{
if(openButton == null)
{
openButton = new JButton("写入文件");
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File file = new File("word.txt");
try
{
FileWriter out = new FileWriter(file);
String s = jTextArea.getText();
out.write(s);
out.close();
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
});
}
openButton.setBounds(80,80,20,18);
return openButton;
}
private JButton closeButton()
{
if(closeButton == null)
{
closeButton = new JButton("读取文件");
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File file = new File("word.txt");
try
{
FileReader in = new FileReader(file);
char[] byt = new char[1024];
int len = in.read(byt);
jTextArea.setText(new String(byt,0,len));
in.close();
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
});
}
openButton.setBounds(80,100,20,18);
return closeButton;
}
public Ftest()
{
super();
initialize();
}
private void initialize()
{
this.setSize(300,200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane()
{
if(jContentPane == null)
{
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJTextArea(),BorderLayout.CENTER);
jContentPane.add(getControlPanel(),BorderLayout.SOUTH);
}
return jContentPane;
}
private JTextArea getJTextArea()
{
return jTextArea;
}
private JPanel getControlPanel()
{
controlPanel.add(openButton);
controlPanel.add(closeButton);
return controlPanel;
}
public static void main(String[] args)
{
Ftest f = new Ftest();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
大神们,我看了好久还是找不出错误