Вот код, который я пишу, чтобы изменить цвет строки, где метр кожи <200, но я сталкиваюсь с исключением нулевого указателя в условии if. Сначала я получаю все данные из базы данных и добавляю их все в табличное представление, чтобы не ожидать исключения нулевого указателя. В чем проблема? </p>
@FXML
TableView<Leather> tableView;
ObservableList<Leather> data = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
tableView.setEditable(true);
codeCol.setCellValueFactory(new PropertyValueFactory<>("code"));
colorCol.setCellValueFactory(new PropertyValueFactory<>("color"));
meterCol.setCellValueFactory(new PropertyValueFactory<>("meter"));
indexCol.setCellFactory(col -> new TableCell<Task, String>() {
@Override
public void updateIndex(int index) {
super.updateIndex(index);
if (isEmpty() || index < 0) {
setText(null);
} else {
setText(Integer.toString(index+1));
}
}
});
data.addAll(storeService.getAll());
tableView.setItems(data);
tableView.setRowFactory(tv -> new TableRow<Leather>(){
@Override
protected void updateItem(Leather item, boolean empty) {
super.updateItem(item,empty);
if (item.getMeter()<200){
setStyle("-fx-background-color: #DB8A6B");
}
}
});
}