Even though I have used SimpleStringProperty and SimpleIntegerProperty, every time I click "List Artists" button gives the following error.
May 03, 2021 9:33:22 PM javafx.scene.control.cell.PropertyValueFactory getCellDataReflectively
WARNING: Can not retrieve property 'name' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@7bcaa928 with provided class type: class sample.model.Artists
java.lang.RuntimeException: java.lang.IllegalAccessException: module javafx.base cannot access class sample.model.Artists (in module MusicUI) because module MusicUI does not open sample.model to javafx.base
at javafx.base/com.sun.javafx.property.PropertyReference.get(PropertyReference.java:176)
at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.getCellDataReflectively(PropertyValueFactory.java:184)
at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:154)
at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:133)
at ....
Controller class having event handler for the button "List Artists" : This error arises when we invoke new Thread(task).start()
public class Controller {
@FXML
public TableView<Artists> artistTable;
@FXML
public void listArtists(){
Task<ObservableList<Artists>> task = new GetAllArtistsTask();
artistTable.itemsProperty().bind(task.valueProperty());
new Thread(task).start();
}
}
class GetAllArtistsTask extends Task {
// following method works correct as I printed the observable list.
@Override
protected ObservableList<Artists> call() throws Exception {
return FXCollections.observableArrayList(DataSource.getInstance().
getArtists(DataSource.ORDER_BY_ASC));
}
}
XML file :
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml/1">
<center>
<TableView fx:id="artistTable" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn prefWidth="${artistTable.width}" text="Name" >
<cellValueFactory>
<!-- This maps to name column in Table artists-->
<PropertyValueFactory property="name"/>
</cellValueFactory>
</TableColumn>
</columns>
<BorderPane.margin>
<Insets right="10.0" />
</BorderPane.margin>
</TableView>
</center>
<right>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="170.00" spacing="20.0" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets right="10.0"/>
</BorderPane.margin>
<Button onAction="#listArtists" maxWidth="Infinity" mnemonicParsing="false" text="List Artists"/>
<Button maxWidth="Infinity" mnemonicParsing="false" text="Show Albums (artist)"/>
<Button maxWidth="Infinity" mnemonicParsing="false" text="Update Artists"/>
</VBox>
</right>
<bottom>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<ProgressBar prefWidth="200.0" progress="0.0">
<HBox.margin>
<Insets left="50.0"/>
</HBox.margin>
</ProgressBar>
</HBox>
</bottom>
</BorderPane>
Artists Class : I used the SimpleIntegerProperty and SimpleStringProperty instead of int and String as specified by : JavaFX 11: IllegalAccessError when creating Label
public class Artists {
private final SimpleIntegerProperty _id;
private final SimpleStringProperty name;
public int get_id() { return _id.get(); }
public String getName() { return name.get();}
public Artists(int _id, String name) {
this._id = new SimpleIntegerProperty();
this._id.set(_id);
this.name = new SimpleStringProperty();
this.name.set(name);
}
@Override
public String toString(){
return "ID: "+ get_id() +", Name: "+ getName();
}
}