I'm trying to set items to the
@FXML
private TableView<Price> pricesTable;
where the following columns defined:
@FXML
private TableColumn<Price, Long> priceId;
@FXML
private TableColumn<Price, Good> priceGood;
@FXML
private TableColumn<Price, MeasurementUnit> priceMeasurement_unit;
@FXML
private TableColumn<Price, TypeOfPrice> type_of_price;
@FXML
private TableColumn<Price, Long> price;
using such code:
private void updatePrices() throws SQLException{
pricesPane.setCenter(pricesTable);
pricesTable.setItems(FXCollections.observableArrayList(pricesService.getPrices()));
pricesTable.getSortOrder().add(priceId);
}
where pricesService is the following:
public class PricesServiceImpl implements PricesService {
private final Dao<Price, Long> pricesDao = DaoFactory.getDao(Price.class);
private Logger log = LogManager.getLogger(PricesServiceImpl.class);
@Override
public List<Price> getPrices() throws SQLException {
try {
List<Price> prices = pricesDao.queryForAll();
return prices;
} catch (SQLException e) {
log.log(Level.DEBUG, e.getMessage());
e.printStackTrace();
}
return Collections.emptyList();
}
@Override
public void removePrice(Price price){
try{
pricesDao.delete(price);
}catch (SQLException e){
log.log(Level.ERROR, e.getMessage());
}
}
@Override
public void savePrice(Long id, Good good, MeasurementUnit measurementUnit, TypeOfPrice typeOfPrice, Long priceValue){
Price price = new Price();
price.setId(id);
price.setGood(good);
price.setMeasurementUnit(measurementUnit);
price.setPrice(priceValue);
price.setTypeOfPrice(typeOfPrice);
try {
pricesDao.create(price);
}catch (SQLException e){
log.log(Level.ERROR, e.getMessage());
}
}
}
On compilation I'm constantly getting an error caused by: java.lang.NullPointerException
on string with setItems. I have several tables that gives the same error on their filling. So I cant figure out what is wrong. Maybe the reason of the error is that I'm trying to fill some columns with objects?
UPD: here is prices service init:
private PricesService pricesService = ServiceProvider.getService(PricesService.class);
serviceProvider is the following:
public class ServiceProvider {
private ServiceProvider() {}
private static Map<Class<? extends Service>, Service> serviceMap = new HashMap<>();
static {
serviceMap.put(AgentsService.class, new AgentsServiceImpl());
serviceMap.put(GoodsService.class, new GoodsServiceImpl());
}
@SuppressWarnings("unchecked")
public static <Type> Type getService(Class<Type> type) {
return (Type) serviceMap.get(type);
}
}