如标题中所述...
@FXML
private TableView<Product> table;
@FXML
private TableColumn<Product, String> iname;
@FXML
private TableColumn<Product, String> ilast;
@FXML
private TableColumn<Product, String> iid;
public ObservableList<Product> data = FXCollections.observableArrayList(
new Product("John", "Smith", "23")
);
@Override
public void initialize(URL location, ResourceBundle resources) {
iname.setCellValueFactory(new PropertyValueFactory<Product, String>("name"));
ilast.setCellValueFactory(new PropertyValueFactory<Product, String>("lastname"));
iid.setCellValueFactory(new PropertyValueFactory<Product, String>("id"));
table.setItems(data);
}
public void addItems(String name, String lastname, String id) {
Product p = new Product(name, hwid, core, os, proc);
data.add(p);
getTable().refresh();
}
public TableView<Product> getTable() {
return table;
}
table.setItems(data);
工作正常,但是如果我尝试通过getter方法刷新表,则会得到NullPointerException。
你能帮我吗?