0

Inventory System for school project Link to full code: https://www.dropbox.com/s/7dqfwmx6gwrenj4/MattNapper.zip?dl=0

not getting data from the InventoryController (ObservableList -Part- allParts) to correct "HomePageController" table(partsTable). Fake data uses InhousePart instance. InHousePart, and OutsourcedPart extends Part(abstract)

public class Inventory {

//declaring arrays for parts, and products
private ObservableList<Product> products = FXCollections.observableArrayList();
private ObservableList<Part> allParts = FXCollections.observableArrayList();



//fake data
InHousePart part1 = new InHousePart (1, 1, "pick", 10.00, 1, 1, 5 );

//adds fake data to "allParts" arraylist
public void addData() {
    allParts.add(part1);
}
 //return method for allParts
  public ObservableList<Part> getPartData() {
    return allParts;
}

HomepageController where table is located

**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    partID.setCellValueFactory(cellData -> cellData.getValue().partIDProperty().asObject());
    partName.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
    InvLvl.setCellValueFactory(cellData -> cellData.getValue().InStockProperty().asObject());
    pCPU.setCellValueFactory(cellData -> cellData.getValue().priceProperty().asObject());
}   


//private Inventory myInv;  is declared above at top

public void setPartsTable(Inventory myInv) {
    this.myInv = myInv;
    // Add array list data to the table

    partsTable.setItems(myInv.getPartData());

}

}

MainApp is calling showPartsView() in start. showPartsView() load Homepage over rootLayout, amd give homepage controller access to main app. juststill no data from Inventory Class

@Override
public void start(Stage stage) throws Exception {
    this.stage = stage;
    this.stage.setTitle("MattNapper");
//calling func
      initRootLayout();
      showPartsView();

}

/**
 * Initializes the root layout.
 */
public void initRootLayout() {
    try {
         //Load root layout from fxml file.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("View_Controller/RootLayout.fxml"));
        rootLayout = (BorderPane) loader.load();

        // Show the scene containing the root layout.
        Scene scene = new Scene(rootLayout);
        stage.setScene(scene);
        stage.show();


    } catch (IOException e) {
        e.printStackTrace();
    }
}

/**
 * Shows the animal overview inside the root layout.
 */
public void showPartsView() {
    try {
        // Load homepage overview.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("View_Controller/HomePage.fxml"));
        AnchorPane homepage = (AnchorPane) loader.load();

        // Set animal overview into the center of root layout.
        rootLayout.setCenter(homepage);

     // Give the controller access to the main app.
    HomePageController controller = loader.getController();
    controller.setPartsTable(inv);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
matt napper
  • 75
  • 10
  • There may be other code issues than those mentioned in the duplicate, if that's the case, let me know and I will reopen. If you do so, provide a full [mcve] inline in the question (not linked), which provides the missing code. – jewelsea Jan 24 '18 at 21:25
  • Actually, looking through your previous question, it seems this was already answered for: [Javafx: incompatible types: int cant be converted to IntegerProperty](https://stackoverflow.com/questions/48430057/javafx-incompatible-types-int-cant-be-converted-to-integerproperty). So if you are still having an issues providing an [mcve] would be mandatory. – jewelsea Jan 25 '18 at 00:31
  • 1
    It was because in the Start method in MainApp I didnt call Inv.addData() because the my fake data in not located in MainApp but in Inventory. – matt napper Jan 25 '18 at 18:17

0 Answers0