我想通过创建该控制器的对象来从一个控制器创建一个按钮,但是在将按钮添加到hbox
时,我得到一个空指针异常。
这是我的代码:
@FXML
private void AddTable1(ActionEvent event)throws Exception
{
List<Button> buttonlist = new ArrayList<Button>();
String sql = "select * from TABLE_NUMBERS";
ResultSet rs = stmt.executeQuery(sql);
int id=1;
while(rs.next())
{
id++;
buttonlist.add(new Button("+tbl_number+"));
}
String tbl_type=combo1.getSelectionModel().getSelectedItem();
String tax = combo2.getSelectionModel().getSelectedItem();
int tbl_number =Integer.parseInt(table_no.getText())+0;
System.out.println(tbl_number);
int max_cap = Integer.parseInt(capa.getText());
String des=desc.getText();
String sql1 ="INSERT INTO Table_Numbers VALUES("+id+",'"+tbl_type+"',"+tbl_number+","+max_cap+",'"+des+"','"+tax+"'"+")";
System.out.println(sql1);
if(!"+table_number+".equals("0"))
{
stmt.execute(sql1);
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("TABLE");
alert.setHeaderText(null);
alert.setContentText("SUCCESSFULLY UPDATED");
alert.showAndWait();
// Stage stage = (Stage)Add.getScene().getWindow();
// stage.close();
}
buttonlist.add(new Button("+tbl_number+"));
for(int i=0;i<buttonlist.size();i++)
{
buttonlist.get(i).setMinWidth(120.0f);
buttonlist.get(i).setWrapText(true);
buttonlist.get(i).setMinHeight(40);
}
Button button1 = new Button("+tbl_number+");
RestaurantsController rc=new RestaurantsController();
System.out.println(buttonlist.size());
for(int i=0; i<=buttonlist.size();i++)
{
rc.hbox.getChildren().addAll(buttonlist.get(0));//null pointer exception
}
}