我正在尝试使windowbuilder gui与其他类的逻辑交互,我想从文本字段中读取并放入Arraylist对象中,只需单击一个按钮,我有两种方法,它们都给了我错误“ AWT-EventQueue-0”线程中的异常java.lang.NullPointerException,这是代码
Button btnNewButton = new JButton("New button");
btnNewButton.setAction(action);
panel.add(btnNewButton);
}
private class SwingAction extends AbstractAction {
public SwingAction() {
putValue(NAME, "SwingAction");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
Board.setname(textField.getText());
Board.newcus();
}
}
方法n°2
btnNewButton.addActionListener(e->{
Board.setname(textField.getText());
Board.newcus();
});
这就是我在船上所做的
public static void setname(String n) {
name=n;
}
public static void newcus() {
Customer a= new Customer();
cus.add(a);
a.setname(name);
System.out.println(a.getname());
}