I'm trying to store an Array containing Car objects in a .dat file and then read them and display on a TableView. It works for the most part but one specific Boolean field "isAvailable" from my Car class refuses to show and gives me an error like this:
WARNING: Can not retrieve property 'isAvailable' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@7e09765f with provided class type: class model.rental.car.Car
java.lang.IllegalStateException: Cannot read from unreadable property isAvailable
My Car class:
public class Car implements Serializable {
private String plateNo;
private String model;
private CarType type;
private Boolean isAvailable;
public Car(String plateNo, String model, CarType type, Boolean isAvailable) {
this.plateNo = plateNo;
this.model = model;
this.type = type;
this.isAvailable = isAvailable;
}
Initializing values for the TableView:
public void initialize(URL arg0, ResourceBundle arg1) {
platNoCol.setCellValueFactory(new PropertyValueFactory<Car, String>("plateNo"));
modelCol.setCellValueFactory(new PropertyValueFactory<Car, String>("model"));
typeCol.setCellValueFactory(new PropertyValueFactory<Car, CarType>("type"));
availabilityCol.setCellValueFactory(new PropertyValueFactory<Car, Boolean>("isAvailable"));
carTableView.setItems(carList);
}
"carList" above is an ObservableList. I get this by getting a List object from the dat file storing a Car[] Array in this way:
public static List<Car> loadCarDB(String fileName) {
List<Car> carList = new ArrayList<Car>();
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream("carDB.dat"));
carList = Arrays.asList((Car[]) in.readObject());
in.close();
} catch (FileNotFoundException e) {
System.out.println("Car database file not found.");
} catch (EOFException e) {
} catch (IOException e) {
System.out.println("Error when processing car database.\n" + e);
} catch (ClassNotFoundException e) {
System.out.println("No car data in database.");
}
return carList;
}
And then converting it to an ObservableList like this:
ObservableList<Car> carList = FXCollections.observableArrayList(model.FileProcessing.loadCarDB("../carDB.dat"));
Main reason I've done most of the things in the way I have is because those are the instructions given for this project. What is the right way to display boolean values in a TableView?