0

I created a tableview in scenebuilder and Ive been trying to add items to a tableView to however I am running into the Can not retrieve property variable in propertyValueFactory) for every variable i have. I belive i have everything correct but i cant see whats wrong in this case Here is the item class:

package application;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

public class Item {
    private SimpleIntegerProperty id;
    private SimpleStringProperty name;
    private SimpleIntegerProperty cost;
    private SimpleIntegerProperty salePrice;
    private SimpleIntegerProperty amount;
    private SimpleIntegerProperty totalCost;
    private SimpleIntegerProperty totalSalePrice;

    public Item(int id, String name, int cost, int salePrice, int amount, int totalCost, int totalSalePrice) {
        super();
        this.id = new SimpleIntegerProperty(id);
        this.name = new SimpleStringProperty(name);
        this.cost = new SimpleIntegerProperty(cost);
        this.salePrice = new SimpleIntegerProperty(salePrice);
        this.amount = new SimpleIntegerProperty(amount);
        this.totalCost = new SimpleIntegerProperty(totalCost);
        this.totalSalePrice = new SimpleIntegerProperty(totalSalePrice);
    }

    public int getId() {
        return id.get();
    }

    public void setId(int id) {
        this.id = new SimpleIntegerProperty(id);
    }

    public String getName() {
        return name.get();
    }

    public void setName(String name) {
        this.name = new SimpleStringProperty(name);
    }

    public int getCost() {
        return cost.get();
    }

    public void setCost(int cost) {
        this.cost =  new SimpleIntegerProperty(cost);
    }

    public int getSalePrice() {
        return salePrice.get();
    }

    public void setSalePrice(int salePrice) {
        this.salePrice =  new SimpleIntegerProperty(salePrice);
    }

    public int getAmount() {
        return amount.get();
    }

    public void setAmount(int amount) {
        this.amount =  new SimpleIntegerProperty(amount);
    }

    public int getTotalCost() {
        return totalCost.get();
    }

    public void setTotalCost(int totalCost) {
        this.totalCost =  new SimpleIntegerProperty(totalCost);
    }

    public int getTotalSalePrice() {
        return totalSalePrice.get();
    }

    public void setTotalSalePrice(int totalSalePrice) {
        this.totalSalePrice =  new SimpleIntegerProperty(totalSalePrice);
    }`

` and here is the controller class

package application;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
// used this video for this tablevie stuff https://www.youtube.com/watch?v=vAmyTJyFXe4
public class InventorySystemController implements Initializable{
    private Stage stage;
    private Scene scene;
    private Parent root;
    @FXML
    private Button removeInventory;

    @FXML
    private Button addInventory;

    @FXML
    private TableView<Item> table;

    @FXML
    private TableColumn<Item,Integer> costColumn;

    @FXML
    private TableColumn<Item,String> nameColumn;

    @FXML
    private TableColumn<Item,Integer> totalCostColumn;

    @FXML
    private TableColumn<Item,Integer> amountColumn;

    @FXML
    private TableColumn<Item,Integer> totalSalePriceColumn;

    @FXML
    private TableColumn<Item,Integer> saleColumn;

    @FXML
    private TableColumn<Item,Integer> idColumn;
    
    
    @FXML
    void swicthToAdd(ActionEvent event) throws IOException {
        // from youtube video https://www.youtube.com/watch?v=hcM-R-YOKkQ
        Parent root = FXMLLoader.load(getClass().getResource("InventorySystemView2.fxml"));
        stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    void swicthToRemove(ActionEvent event) {

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        idColumn.setCellValueFactory(new PropertyValueFactory<>("Id"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("Name"));
        costColumn.setCellValueFactory(new PropertyValueFactory<>("Cost"));
        saleColumn.setCellValueFactory(new PropertyValueFactory<>("SalePrice"));
        amountColumn.setCellValueFactory(new PropertyValueFactory<>("Amount"));
        totalCostColumn.setCellValueFactory(new PropertyValueFactory<>("TotalCost"));
        totalSalePriceColumn.setCellValueFactory(new PropertyValueFactory<>("TotalSalePrice"));
        
        table.setItems(list);
    }
    ObservableList<Item> list=FXCollections.observableArrayList(
            new Item(1,"i",3,4,5,6,2)
            );
        
    
    

}

and finnaly here is the error output

Nov. 28, 2022 7:36:22 P.M. javafx.scene.control.cell.PropertyValueFactory getCellDataReflectively
WARNING: Can not retrieve property 'Id' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@72a907f5 with provided class type: class application.Item
java.lang.RuntimeException: java.lang.IllegalAccessException: module javafx.base cannot access class application.Item (in module ProjectReviewerCollection) because module ProjectReviewerCollection does not open application 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 javafx.controls/javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:593)
    at javafx.controls/javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:578)
    at javafx.controls/javafx.scene.control.TableCell.updateItem(TableCell.java:646)
    at javafx.controls/javafx.scene.control.TableCell.indexChanged(TableCell.java:469)
    at javafx.controls/javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
    at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:539)
    at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:159)
    at javafx.controls/javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:89)
    at javafx.controls/javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:213)
    at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
    at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
    at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
    at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9547)
    at javafx.graphics/javafx.scene.Node.applyCss(Node.java:9634)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1743)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1720)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1846)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2758)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1239)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1750)
    at javafx.graphics/javafx.scene.Scene$2.preferredSize(Scene.java:393)
    at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
    at javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1111)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
    at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1187)
    at javafx.graphics/javafx.stage.Window.show(Window.java:1202)
    at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
    at ProjectReviewerCollection/application.Main.start(Main.java:24)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessException: module javafx.base cannot access class application.Item (in module ProjectReviewerCollection) because module ProjectReviewerCollection does not open application to javafx.base
    at javafx.base/com.sun.javafx.property.MethodHelper.invoke(MethodHelper.java:69)
    at javafx.base/com.sun.javafx.property.PropertyReference.get(PropertyReference.java:174)
    ... 46 more







I cant fit all of it here but the error code happens for all other varibales not only ID and it happens to name,etc

I had decalred the type of the table and columns to be of the Item class whihc is the class I created, I also made sure when doing the propertyvalueFactory to use the names that would help them locate the getter methods as well.

  • 3
    The stack trace tells you the problem: "java.lang.RuntimeException: java.lang.IllegalAccessException: module javafx.base cannot access class application.Item (in module ProjectReviewerCollection) because module ProjectReviewerCollection does not open application to javafx.base ". You need to explicitly open your package if you want JavaFX to access it by reflection. A far better solution is not to use `PropertyValueFactory`: there is absolutely no need to use this legacy class in a modern JavaFX application. – James_D Nov 29 '22 at 03:15
  • 3
    Also note that your model class `Item` is incorrectly implemented. Your `set` methods should not create new property instances, but should change the value of the existing property instance. You should also provide "property accessor" methods (`public IntegerProperty idProperty() { ... }` etc.). See the duplicate (or the [tutorial](https://docs.oracle.com/javafx/2/binding/jfxpub-binding.htm)) for the correct implementation. – James_D Nov 29 '22 at 03:48
  • as to future problems: please do some research before asking (reading the api doc, searching for the error message, studying related QAs here on SO - there's a list of FAQs in the javafx tag wiki .. ) .. if still stuck, provide a [mcve] (mind the __M__! nothing unrelated, though complete with stacktrace an runnable as-is) demonstrating the problem – kleopatra Nov 29 '22 at 11:14

0 Answers0