Moving from one window to another

Mataske :

New to coding, let alone java and javaFX. I'm not sure where I'm messing up on moving from the home window to any other one and could use some help figuring it out.

The homewindow opens fine but when trying to move to any other screen, for example AddPart it gives the error log at the bottom of the page. It does this with every single page, so I'm assuming it's something with how I'm trying to load the pages.

HomeWindowController:

package ViewController;

import Model.Inventory;
import static Model.Inventory.getPartInventory;
import static Model.Inventory.getProductInventory;
import static Model.Inventory.removePart;
import static Model.Inventory.removeProduct;
import static Model.Inventory.validatePartDelete;
import Model.Part;
import Model.Product;
import Software1C482.InventorySystem;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
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.Alert;
import javafx.scene.control.Alert.AlertType;

import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
 * FXML Controller class
 *
 * @author Andrew
 */

//It's the home window.
public class HomeWindowController implements Initializable {

//Declaring the FXML parts.
    @FXML
    private TableView<Product> TableProduct;
    @FXML
    private TableColumn<Product, Integer> ProductID, ProductInventoryLevel;
    @FXML
    private TableColumn<Product, String> ProductName;
    @FXML
    private TableColumn<Product, Double> ProductPPU;
    @FXML
    private Button ButtonProductAdd;
    @FXML
    private Button ButtonProductModify;
    @FXML
    private Button ButtonProductDelete;
    @FXML
    private Button ButtonPartSearch;
    @FXML
    private TableView<Part> TablePart;
    @FXML
    private TableColumn<Part, Integer> PartID, PartInventoryLevel;
    @FXML
    private TableColumn<Part, String> PartName;
    @FXML
    private TableColumn<Part, Double> PartPPU;
    @FXML
    private TextField SearchFieldPart;
    @FXML
    private TextField SearchFieldProduct;

    private static Part modifyPart;
    private static int modifyPartIndex;
    private static Product modifyProduct;
    private static int modifyProductIndex;

    public static int partToModifyIndex() {
        return modifyPartIndex;
    }

    public static int productToModifyIndex() {
        return modifyProductIndex;
    }

    public HomeWindowController() {
    }

    @FXML
    void HomeExitClick(ActionEvent event) {

        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.initModality(Modality.NONE);
        alert.setTitle("Confirmation");
        alert.setHeaderText("Confirm Exit");
        alert.setContentText("Are you sure you want to exit?");
        Optional<ButtonType> result = alert.showAndWait();

        if (result.get() == ButtonType.OK) {
            System.exit(0);
        } else {
            System.out.println("Please resume completing form.");
        }
    }

    @FXML
    void HomeAddPartClick(ActionEvent event) throws IOException {

        Parent addPart = FXMLLoader.load(getClass().getResource("AddPart.fxml"));
        Scene scene = new Scene(addPart);
        Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    @FXML
    void HomeAddProductClick(ActionEvent event) throws IOException {

        Parent addProducts = FXMLLoader.load(getClass().getResource("AddProduct.fxml"));
        Scene scene = new Scene(addProducts);
        Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    @FXML
    void HomeModifyPartClick(ActionEvent event) throws IOException {

        modifyPart = TablePart.getSelectionModel().getSelectedItem();
        modifyPartIndex = getPartInventory().indexOf(modifyPart);
        Parent modifyParts = FXMLLoader.load(getClass().getResource("ModifyPart.fxml"));
        Scene scene = new Scene(modifyParts);
        Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    @FXML
    void HomeModifyProductClick(ActionEvent event) throws IOException {

        modifyProduct = TableProduct.getSelectionModel().getSelectedItem();
        modifyProductIndex = getProductInventory().indexOf(modifyProduct);
        Parent modifyProducts = FXMLLoader.load(getClass().getResource("ModifyProduct.fxml"));
        Scene scene = new Scene(modifyProducts);
        Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
        window.setScene(scene);
        window.show();
    }

    @FXML
    void HomeSearchProductsBtn(ActionEvent event) throws IOException {
        String searchProd = SearchFieldProduct.getText();
        int prodIndex = -1;
        if (Inventory.lookupProduct(searchProd) == -1) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Search Error");
            alert.setHeaderText("Product not found.");
            alert.setContentText("The text entered does not match any Product.");
            alert.showAndWait();
        } else {
            prodIndex = Inventory.lookupProduct(searchProd);
            Product tempProd = Inventory.getProductInventory().get(prodIndex);
            ObservableList<Product> tempProdList = FXCollections.observableArrayList();
            tempProdList.add(tempProd);
            TableProduct.setItems(tempProdList);
        }
    }

    @FXML
    void HomeDeleteProductBtn(ActionEvent event) throws IOException {
        Product product = TableProduct.getSelectionModel().getSelectedItem();
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.initModality(Modality.NONE);
        alert.setTitle("Confirm Delete");
        alert.setHeaderText("Confirm?");
        alert.setContentText("Are you sure you want to delete " + product.getProductName() + "?");
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK) {
            removeProduct(product);
            updateProductTableView();
            System.out.println("Product " + product.getProductName() + " was removed.");
        } else {
            System.out.println("Product " + product.getProductName() + " was not removed.");
        }
    }

    @FXML
    void PartSearchOnAction(ActionEvent event) throws IOException {
        String searchPart = SearchFieldPart.getText();
        int partIndex = -1;
        if (Inventory.lookupPart(searchPart) == -1) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Search Error");
            alert.setHeaderText("Part not found.");
            alert.setContentText("The text entered does not match any Part.");
            alert.showAndWait();
        } else {
            partIndex = Inventory.lookupPart(searchPart);
            Part tempPart = Inventory.getPartInventory().get(partIndex);
            ObservableList<Part> tempProdList = FXCollections.observableArrayList();
            tempProdList.add(tempPart);
            TablePart.setItems(tempProdList);
        }
    }

    @FXML
    void HomeDeletePartOnAction(ActionEvent event) throws IOException {
        Part part = TablePart.getSelectionModel().getSelectedItem();
        if (validatePartDelete(part)) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Part Delete Error.");
            alert.setHeaderText("Part cannot be removed.");
            alert.setContentText("This part is used in a product.");
            alert.showAndWait();
        } else {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.initModality(Modality.NONE);
            alert.setTitle("Product Delete");
            alert.setHeaderText("Confirm?");
            alert.setContentText("Are you sure you want to delete " + part.getPartName() + "?");
            Optional<ButtonType> result = alert.showAndWait();

            if (result.get() == ButtonType.OK) {
                removePart(part);
                updatePartTableView();
                System.out.println("Part " + part.getPartName() + " was removed.");
            } else {
                System.out.println("Part " + part.getPartName() + " was not removed.");
            }
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        PartID.setCellValueFactory(cellData -> cellData.getValue().partIDProperty().asObject());
        PartName.setCellValueFactory(cellData -> cellData.getValue().partNameProperty());
        PartInventoryLevel.setCellValueFactory(cellData -> cellData.getValue().partInvProperty().asObject());
        PartPPU.setCellValueFactory(cellData -> cellData.getValue().partPriceProperty().asObject());
        ProductID.setCellValueFactory(cellData -> cellData.getValue().productIDProperty().asObject());
        ProductName.setCellValueFactory(cellData -> cellData.getValue().productNameProperty());
        ProductInventoryLevel.setCellValueFactory(cellData -> cellData.getValue().productInvProperty().asObject());
        ProductPPU.setCellValueFactory(cellData -> cellData.getValue().productPriceProperty().asObject());
        updatePartTableView();
        updateProductTableView();
    }

    public void updatePartTableView() {
        TablePart.setItems(getPartInventory());
    }

    public void updateProductTableView() {
        TableProduct.setItems(getProductInventory());
    }

    public void setMainApp(InventorySystem mainApp) {
        updatePartTableView();
        updateProductTableView();
    }
}

AddPartController:

package ViewController;

import Model.InhousePart;
import Model.Inventory;
import Model.OutsourcedPart;
import Model.Part;
import javafx.scene.control.Label;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
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.Alert;
import javafx.scene.control.Alert.AlertType;

import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Andrew
 */
public class AddPartController implements Initializable {

    @FXML
    private RadioButton APRadialInhouse;
    @FXML
    private RadioButton APRadialOutsourced;
    @FXML
    private TextField IDField;
    @FXML
    private TextField NameField;
    @FXML
    private TextField InvField;
    @FXML
    private TextField PPUField;
    @FXML
    private TextField SwapField;
    @FXML
    private TextField MinField;
    @FXML
    private TextField MaxField;
    @FXML
    private Button APSave;
    @FXML
    private Button APButtonCancel;
    @FXML
    private Label APSwapLabel;

    private boolean isOutsourced;
    private String exceptionMessage = new String();
    private int partID;

    /**
     * Initializes the controller class.
     */
    //Initialize Controller
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        partID = Inventory.getPartIDCount();
        IDField.setText("AUTO GEN: " + partID);
    }
    //Inhouse Radial
    @FXML
    private void AddPartsInHouseRadio(ActionEvent event) {
        isOutsourced = false;
        APSwapLabel.setText("Machine ID");
    }
    //Outsourced Radial
    @FXML
    private void APOutsourcedOnAction(ActionEvent event) {
        isOutsourced = true;
        APSwapLabel.setText("Company Name");
    }
    //Save Button
    @FXML
    private void APSaveOnAction(ActionEvent event) throws IOException {
        String partName = NameField.getText();
        String partInv = InvField.getText();
        String partPrice = PPUField.getText();
        String partMin = MinField.getText();
        String partMax = MaxField.getText();
        String partDyn = SwapField.getText();

        try {
            exceptionMessage = Part.isPartValid(partName, Integer.parseInt(partMin), Integer.parseInt(partMax), Integer.parseInt(partInv), Double.parseDouble(partPrice), exceptionMessage);
            if (exceptionMessage.length() > 0) {
                Alert alert = new Alert(AlertType.INFORMATION);
                alert.setTitle("Error Adding Part");
                alert.setHeaderText("Error");
                alert.setContentText(exceptionMessage);
                alert.showAndWait();
                exceptionMessage = "";
            } else {
                if (isOutsourced == false) {
                    InhousePart iPart = new InhousePart();

                    iPart.setPartID(partID);
                    iPart.setPartName(partName);
                    iPart.setPartPrice(Double.parseDouble(partPrice));
                    iPart.setPartInStock(Integer.parseInt(partInv));
                    iPart.setPartMin(Integer.parseInt(partMin));
                    iPart.setPartMax(Integer.parseInt(partMax));
                    iPart.setPartMachineID(Integer.parseInt(partDyn));
                    Inventory.addPart(iPart);
                } else {
                    OutsourcedPart oPart = new OutsourcedPart();

                    oPart.setPartID(partID);
                    oPart.setPartName(partName);
                    oPart.setPartPrice(Double.parseDouble(partPrice));
                    oPart.setPartInStock(Integer.parseInt(partInv));
                    oPart.setPartMin(Integer.parseInt(partMin));
                    oPart.setPartMax(Integer.parseInt(partMax));
                    oPart.setPartCompanyName(partDyn);
                    Inventory.addPart(oPart);
                }

                Parent partsSave = FXMLLoader.load(getClass().getResource("HomeWindow.fxml"));
                Scene scene = new Scene(partsSave);
                Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
                window.setScene(scene);
                window.show();
            }
        } catch (NumberFormatException e) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Error Adding Part");
            alert.setHeaderText("Error");
            alert.setContentText("Form contains blank fields.");
            alert.showAndWait();
        }
    }
    //Cancel Button
    @FXML
    private void APButtonCancelOnAction(ActionEvent event) throws IOException {

        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.initModality(Modality.NONE);
        alert.setTitle("Confirmation");
        alert.setHeaderText("Confirm Delete");
        alert.setContentText("Are you sure you want to delete part " + NameField.getText() + "?");
        Optional<ButtonType> result = alert.showAndWait();

        if (result.get() == ButtonType.OK) {
            Parent partsCancel = FXMLLoader.load(getClass().getResource("HomeWindow.fxml"));
            Scene scene = new Scene(partsCancel);
            Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
            window.setScene(scene);
            window.show();
        } else {
            System.out.println("Cancel has been clicked.");
        }

    }
}

AddPart.FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.Scene?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<Scene xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ViewController.AddPartController">
    <AnchorPane prefHeight="473.0" prefWidth="513.0">
      <children>
         <Label layoutX="24.0" layoutY="24.0" text="Add Part">
            <font>
               <Font size="18.0" />
            </font>
         </Label>
         <RadioButton fx:id="APRadialInhouse" layoutX="163.0" layoutY="29.0" mnemonicParsing="false" onAction="#AddPartsInHouseRadio" text="In-House">
      </RadioButton>
         <RadioButton fx:id="APRadialOutsourced" layoutX="283.0" layoutY="29.0" mnemonicParsing="false" onAction="#APOutsourcedOnAction" text="Outsourced" />
         <Label layoutX="80.0" layoutY="204.0" text="Inv" />
         <Label layoutX="80.0" layoutY="109.0" text="ID" />
         <Label layoutX="80.0" layoutY="158.0" text="Name" />
         <Label layoutX="80.0" layoutY="302.0" text="Max" />
         <Label layoutX="80.0" layoutY="251.0" text="Price/Cost" />
         <Label layoutX="253.0" layoutY="302.0" text="Min" />
         <Label fx:id="APSwapLabel" layoutX="82.0" layoutY="344.0" text="Machine ID" />
         <TextField fx:id="IDField" disable="true" editable="false" layoutX="179.0" layoutY="105.0" promptText="ID" />
         <TextField fx:id="NameField" layoutX="179.0" layoutY="154.0" promptText="Part Name" />
         <TextField fx:id="InvField" layoutX="179.0" layoutY="200.0" promptText="Inventory" />
         <TextField fx:id="PPUField" layoutX="179.0" layoutY="247.0" promptText="Price/Cost" />
         <TextField fx:id="SwapField" layoutX="182.0" layoutY="340.0" prefHeight="25.0" prefWidth="106.0" promptText="Company Name" />
         <TextField fx:id="MinField" layoutX="292.0" layoutY="298.0" prefHeight="22.0" prefWidth="62.0" promptText="Min" />
         <TextField fx:id="MaxField" layoutX="179.0" layoutY="298.0" prefHeight="22.0" prefWidth="62.0" promptText="Max" />
         <Button fx:id="APSave" layoutX="301.0" layoutY="407.0" mnemonicParsing="false" onAction="#APSaveOnAction" prefHeight="40.0" prefWidth="82.0" text="Save" />
         <Button fx:id="APButtonCancel" layoutX="399.0" layoutY="407.0" mnemonicParsing="false" onAction="#APButtonCancelOnAction" prefHeight="40.0" prefWidth="82.0" text="Cancel" />
      </children></AnchorPane>
</Scene>

Error code:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
    at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8879)
    at javafx.controls/javafx.scene.control.Button.fire(Button.java:200)
    at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
    at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3851)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    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:830)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
    at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
    at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1782)
    ... 47 more
Caused by: java.lang.ClassCastException: class javafx.scene.Scene cannot be cast to class javafx.scene.Parent (javafx.scene.Scene and javafx.scene.Parent are in module javafx.graphics of loader 'app')
    at InventorySystem/ViewController.HomeWindowController.HomeAddPartClick(HomeWindowController.java:115)
    ... 58 more
adxl :

The problem here is casting Parent to Scene.

Two solutions for you :

1. Changing the fxml root to an Node :

For example your fxml with start like that

<AnchorPane prefHeight="473.0" prefWidth="513.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ViewController.AddPartController">
      <children>
         <Label layoutX="24.0" layoutY="24.0" text="Add Part">
           ...

Instead of

<Scene xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ViewController.AddPartController">
    <AnchorPane prefHeight="473.0" prefWidth="513.0">
      <children>
         <Label layoutX="24.0" layoutY="24.0" text="Add Part">
            ...

2. Changing the way you create your Scene :

 //REMOVE THE PARENT
 //Parent addPart = FXMLLoader.load(getClass().getResource("AddPart.fxml"));
 Scene scene = FXMLLoader.load(getClass().getResource("AddPart.fxml"));

Hope it helps

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=169155&siteId=1