所以我做了一些更改(给我的nullCs的generateCsvFile是底部的那个,我删除了我的Test()方法中的那个)但它仍然说是null
private class thehandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(Nummer)) {
NummerS = String.format(e.getActionCommand());
} else if (e.getSource() == Locatie) {
LocatiesS = String.format(e.getActionCommand());
} else if (e.getSource() == Login) {
LoginS = String.format(e.getActionCommand());
} else if (e.getSource() == Datum) {
DatumS = String.format(e.getActionCommand());
} else if (e.getSource() == Nummer1) {
Nummer1S = String.format(e.getActionCommand());
} else if (e.getSource() == Nummer5) {
Nummer5S = String.format(e.getActionCommand());
} else if (e.getSource().equals(save)) {
generateCsvFile("c:\\testss.csv");
System.out.println(NummerS);
System.out.println("Debug");
}
}
// JOptionPane.showMessageDialog(null, string);
}
答案 0 :(得分:0)
在实例化处理程序之前,您似乎正在调用generateCsv()方法。是的,您正在分配变量,但是在编写完文件后就是这样做了。把它改成这个。
public Test() {
super("Plankske 1");
setLayout(new FlowLayout());
Nummer = new JTextField(10);
add(Nummer);
Locatie = new JTextField("980000119818");
add(Locatie);
Login = new JTextField(10);
add(Login);
Datum = new JTextField(10);
add(Datum);
Nummer1 = new JTextField(10);
add(Nummer1);
Nummer5 = new JTextField(10);
add(Nummer5);
save = new JButton("Save");
add(save);
thehandler handler = new thehandler();
Nummer.addActionListener(handler);
Locatie.addActionListener(handler);
Login.addActionListener(handler);
Datum.addActionListener(handler);
Nummer1.addActionListener(handler);
Nummer5.addActionListener(handler);
save.addActionListener(handler);
generateCsvFile("c:\\test.csv");
}