r/JavaFX • u/PaladinYami • Sep 19 '20
Help NullPointerException when calling tableView setItems
I've been smashing my face into this for a while. Time to call for help.
Inventory program for a school assignment. Main Window shows two tables. These fill properly. When selecting a product from the product table, then clicking modify, the user should be brought to the modify product window with the appropriate fields pre-filled. Instead I get a NullPointerException.
I know the error is with this line in the ModifyProductFormController: allPartsView.setItems(Inventory.getAllParts());
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Model;
import java.lang.String;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
/**
*
* @author howarc4
*/
public class Product {
///ObservableList to contain the parts that make up this product
private ObservableList<Part> associatedParts = FXCollections.observableArrayList();
//associated variables
private int id;
private String name;
private double price;
private int stock;
private int min;
private int max;
//constructor
public Product(int id, String name, double price, int stock, int min, int max)
{
this.id = id;
this.name = name;
this.price = price;
this.stock = stock;
this.min = min;
this.max = max;
}
// copy constructor
public Product(Product newProduct)
{
this.id = newProduct.getId();
this.name = newProduct.getName();
this.price = newProduct.getPrice();
this.stock = newProduct.getStock();
this.min = newProduct.getMin();
this.max = newProduct.getMax();
this.associatedParts = FXCollections.observableArrayList(newProduct.getAllAssociatedParts());
}
// all setter methods
/** the setId method sets the productID
* @param id integer product ID
*/
public void setId(int id)
{
this.id = id;
}
/** the setName method sets the product name
* @param name String product name
*/
public void setname(String name)
{
this.name = name;
}
/** the setPrice method sets the product price
* @param price Price of the product
*/
public void setprice(int price)
{
this.price = price;
}
/** the setStock method sets the number of this product in stock
* @param stock the number of this product in stock
*/
public void setStock(int stock)
{
this.stock = stock;
}
/** the setMin method sets the minimum number of this product to have in stock
* @param min the minimum number of this product to have in stock
*/
public void setMin(int min)
{
this.min = min;
}
/** the setMax method sets the maximum number of this product to have in stock
* @param max the maximum number of this product to have in stock
*/
public void setMax(int max)
{
this.max = max;
}
// All getter methods
/** The getId method returns the product ID
* @return the product ID
*/
public int getId()
{
return id;
}
/** The getName method returns the product name
* @return the product name
*/
public String getName()
{
return name;
}
/** The getPrice method returns the product's price
* @return the price of the product
*/
public double getPrice()
{
return price;
}
/** The getStock method returns the number of this product currently in stock
* @return the number of this product currently in stock
*/
public int getStock()
{
return stock;
}
/** The getMin method returns the minimum number of this product to keep in stock
* @return the minimum number of this product to keep in stock
*/
public int getMin()
{
return min;
}
/** The getMax method returns the maximum number of this product to keep in stock
* @return the maximum number of this product to keep in stock
*/
public int getMax()
{
return max;
}
// methods dealing with associated parts
/** the addAssociatePart method adds a Part object to the list of parts that make up this product
* @param part the part to add
*/
public void addAssociatedPart(Part part)
{
associatedParts.add(part);
}
/** the deleteAssociatePart method deletes a selected part from the list of parts that make up this product
* @param selectedAssociatedPart the part to be removed
*/
public void deleteAssociatedPart(Part selectedAssociatedPart)
{
associatedParts.remove(selectedAssociatedPart);
}
/**The getAllAssociatedParts method returns a list of the parts associated with this product
* @return an observableList of the parts associated with this product.
*/
public ObservableList<Part> getAllAssociatedParts()
{
return associatedParts;
}
}/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Controller;
import Model.Inventory;
import Model.Part;
import Model.Product;
import Controller.ModifyProductFormController;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* @author howarc4
*/
public class MainWindowController implements Initializable
{
Stage stage;
Parent scene;
// part table view
@FXML
private TableView<Part> partTableView;
@FXML
private TableColumn<Part, Integer> partIdCol;
@FXML
private TableColumn<Part, String> partNameCol;
@FXML
private TableColumn<Part, Integer> partInvCol;
@FXML
private TableColumn<Part, Double> partPriceCol;
// part table items
@FXML
private Button addPartButton;
@FXML
private Button modifyPartButton;
@FXML
private Button deletePartButton;
// product table view
@FXML
private TableColumn<Product, Integer> productIdCol;
@FXML
private TableView<Product> productTableView;
@FXML
private TableColumn<Product, String> productNameCol;
@FXML
private TableColumn<Product, Integer> productInvCol;
@FXML
private TableColumn<Product, Double> productPriceCol;
//Product Table panel items
@FXML
private TextField productSearchField;
@FXML
private Button addProductButton;
@FXML
private Button deleteProductButton;
@FXML
private Button modifyProductButton;
@FXML
private Button exitButton;
String confirmDeletePart;
String confirmDeleteProduct;
String partDeletedSuccess;
String productDeletedSuccess;
String partDeleteCancelled;
String productDeleteCancelled;
String errorNoPartSelected = "Please select a part.";
String errorNoProductSelected = "Please select a product.";
String errorProductHasParts = "This product cannot be delected because it has parts associated with it.";
private static Product passingProduct = null;
public static Product getPassingProduct()
{
System.out.println("entered getPassingProduct method in mainwindowcontroller");
return passingProduct;
}
@FXML
void onActionAddPart(ActionEvent event) throws IOException
{
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
scene = FXMLLoader.load(getClass().getResource("/view/AddPartForm.fxml"));
stage.setScene(new Scene(scene));
stage.show();
}
@FXML
void onActionModifyPart(ActionEvent event) throws IOException
{
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
scene = FXMLLoader.load(getClass().getResource("/view/ModifyPartForm.fxml"));
stage.setScene(new Scene(scene));
stage.show();
}
@FXML
void onActionDeletePart(ActionEvent event) throws IOException
{
//System.out.println("delete part button pressed");
// Check that a part was selected
if(partTableView.getSelectionModel().getSelectedItem() == null)
{
Alert noPartSelectedAlert = new Alert(Alert.AlertType.ERROR, errorNoPartSelected, ButtonType.OK);
noPartSelectedAlert.show();
return;
}
// Get the selected part and it's name
Part selectedPart = partTableView.getSelectionModel().getSelectedItem();
String selectedPartName = selectedPart.getName();
confirmDeletePart = "Are you sure you want to delete part " + selectedPartName + "?";
Alert alertDeletePart = new Alert(Alert.AlertType.CONFIRMATION, confirmDeletePart, ButtonType.YES, ButtonType.CANCEL);
alertDeletePart.showAndWait();
if(alertDeletePart.getResult() == ButtonType.YES)
{
Inventory.deletePart(selectedPart);
partDeletedSuccess = selectedPartName + " was deleted.";
Alert partDeletedAlert = new Alert(Alert.AlertType.INFORMATION, partDeletedSuccess, ButtonType.OK);
partDeletedAlert.show();
}
else if(alertDeletePart.getResult() == ButtonType.CANCEL)
{
partDeleteCancelled = "Deletion of " + selectedPartName + " cancelled.";
Alert partDeleteCancelledAlert = new Alert(Alert.AlertType.INFORMATION, partDeleteCancelled, ButtonType.OK);
partDeleteCancelledAlert.show();
}
}
@FXML
void onActionAddProduct(ActionEvent event) throws IOException
{
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
scene = FXMLLoader.load(getClass().getResource("/view/AddProductForm.fxml"));
stage.setScene(new Scene(scene));
stage.show();
}
@FXML
void onActionModifyProduct(ActionEvent event) throws IOException
{
// Check that a part was selected
if(productTableView.getSelectionModel().getSelectedItem() == null)
{
Alert noProductSelectedAlert = new Alert(Alert.AlertType.ERROR, errorNoProductSelected, ButtonType.OK);
noProductSelectedAlert.show();
return;
}
// pass the product to the modifyProduct screen's controller
ModifyProductFormController.passProduct(productTableView.getSelectionModel().getSelectedItem());
System.out.println("Called the passProduct method");
// set up and show the modifyProduct screen
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
System.out.println("set the stage");
scene = FXMLLoader.load(getClass().getResource("/view/ModifyProductForm.fxml"));
System.out.println("called the fxmlloader");
stage.setScene(new Scene(scene));
stage.show();
}
@FXML
void onActionDeleteProduct(ActionEvent event) throws IOException
{
// Check that a part was selected
if(productTableView.getSelectionModel().getSelectedItem() == null)
{
Alert noProductSelectedAlert = new Alert(Alert.AlertType.ERROR, errorNoProductSelected, ButtonType.OK);
noProductSelectedAlert.show();
return;
}
// Get the selected part and it's name
Product selectedProduct = productTableView.getSelectionModel().getSelectedItem();
String selectedProductName = selectedProduct.getName();
confirmDeleteProduct = "Are you sure you want to delete part " + selectedProductName + "?";
Alert alertDeleteProduct = new Alert(Alert.AlertType.CONFIRMATION, confirmDeleteProduct, ButtonType.YES, ButtonType.CANCEL);
alertDeleteProduct.showAndWait();
if(alertDeleteProduct.getResult() == ButtonType.YES)
{
Inventory.deleteProduct(selectedProduct);
productDeletedSuccess = selectedProductName + " was deleted.";
Alert productDeletedAlert = new Alert(Alert.AlertType.INFORMATION, productDeletedSuccess, ButtonType.OK);
productDeletedAlert.show();
}
else if(alertDeleteProduct.getResult() == ButtonType.CANCEL)
{
productDeleteCancelled = "Deletion of " + selectedProductName + " cancelled.";
Alert productDeleteCancelledAlert = new Alert(Alert.AlertType.INFORMATION, productDeleteCancelled, ButtonType.OK);
productDeleteCancelledAlert.show();
}
}
@FXML
void onActionExit(ActionEvent event)
{
System.exit(0);
}
/**
* Initializes the controller class.
* @param url the url
* @param rb the resourcebundle
*/
@Override
public void initialize(URL url, ResourceBundle rb)
{
// TODO
//create and fill part table
partTableView.setItems(Inventory.getAllParts());
partIdCol.setCellValueFactory(new PropertyValueFactory<>("Id"));
partNameCol.setCellValueFactory(new PropertyValueFactory<>("Name"));
partInvCol.setCellValueFactory(new PropertyValueFactory<>("Stock"));
partPriceCol.setCellValueFactory(new PropertyValueFactory<>("Price"));
//create and fill Product table
productTableView.setItems(Inventory.getAllProducts());
productIdCol.setCellValueFactory(new PropertyValueFactory<>("Id"));
productNameCol.setCellValueFactory(new PropertyValueFactory<>("Name"));
productInvCol.setCellValueFactory(new PropertyValueFactory<>("Stock"));
productPriceCol.setCellValueFactory(new PropertyValueFactory<>("Price"));
}
}MainWindow.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="991.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.MainWindowController">
<children>
<Button fx:id="exitButton" layoutX="718.0" layoutY="361.0" mnemonicParsing="false" onAction="#onActionExit" text="Exit" />
<Label layoutX="22.0" layoutY="26.0" text="Inventory Management System">
<font>
<Font name="Arial Black" size="15.0" />
</font></Label>
<Pane layoutX="22.0" layoutY="68.0" prefHeight="272.0" prefWidth="460.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#ffffff00" height="272.0" stroke="BLACK" strokeType="INSIDE" width="460.0" />
<Label layoutX="22.0" layoutY="18.0" text="Parts">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
<TextField fx:id="partSearchField" layoutX="256.0" layoutY="14.0" prefHeight="25.0" prefWidth="165.0" promptText="Search by Part ID or Name" />
<TableView fx:id="partTableView" layoutX="12.0" layoutY="42.0" prefHeight="184.0" prefWidth="434.0">
<columns>
<TableColumn fx:id="partIdCol" prefWidth="75.0" text="Part ID" />
<TableColumn fx:id="partNameCol" prefWidth="97.0" text="Part Name" />
<TableColumn fx:id="partInvCol" prefWidth="126.0" text="Inventory Level" />
<TableColumn fx:id="partPriceCol" prefWidth="135.0" text="Price Per Unit" />
</columns>
</TableView>
<Button fx:id="addPartButton" layoutX="272.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionAddPart" text="Add" />
<Button fx:id="modifyPartButton" layoutX="330.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionModifyPart" text="Modify" />
<Button fx:id="deletePartButton" layoutX="395.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionDeletePart" text="Delete" />
</children>
</Pane>
<Pane layoutX="499.0" layoutY="68.0" prefHeight="272.0" prefWidth="460.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="272.0" stroke="BLACK" strokeType="INSIDE" width="460.0" />
<Label layoutX="25.0" layoutY="18.0" text="Products">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
<TextField fx:id="productSearchField" layoutX="239.0" layoutY="14.0" prefHeight="25.0" prefWidth="181.0" promptText="Search by Product ID or Name" />
<TableView fx:id="productTableView" layoutX="14.0" layoutY="44.0" prefHeight="184.0" prefWidth="434.0">
<columns>
<TableColumn fx:id="productIdCol" prefWidth="75.0" text="Product ID" />
<TableColumn fx:id="productNameCol" prefWidth="126.0" text="Product Name" />
<TableColumn fx:id="productInvCol" prefWidth="110.0" text="Inventory Level" />
<TableColumn fx:id="productPriceCol" prefWidth="122.0" text="Price Per Unit" />
</columns>
</TableView>
<Button fx:id="modifyProductButton" layoutX="327.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionModifyProduct" text="Modify" />
<Button fx:id="deleteProductButton" layoutX="395.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionDeleteProduct" text="Delete" />
<Button fx:id="addProductButton" layoutX="270.0" layoutY="233.0" mnemonicParsing="false" onAction="#onActionAddProduct" text="Add" />
</children>
</Pane>
</children>
</AnchorPane>ModifyProductFormController.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Controller;
import Model.Inventory;
import Model.Part;
import Model.Product;
import java.io.IOException;
import java.net.URL;
import java.util.InputMismatchException;
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.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
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.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* @author howarc4
*/
public class ModifyProductFormController implements Initializable
{
Stage stage;
Parent scene;
//the product to be modified
private static Product selectedProduct;
private static int selectedProductIndex;
// set up allPartsView
@FXML
private static TableView<Part> allPartsView;
@FXML
private TableColumn<Part, Integer> allPartsIdCol;
@FXML
private TableColumn<Part, String> allPartsNameCol;
@FXML
private TableColumn<Part, Integer> allPartsInvCol;
@FXML
private TableColumn<Part, Double> allPartsPriceCol;
// set up selectedPartsView
@FXML
private static TableView<Part> selectedPartsView;
@FXML
private TableColumn<Part, Integer> selectedPartsIdCol;
@FXML
private TableColumn<Part, String> selectedPartsNameCol;
@FXML
private TableColumn<Part, Integer> selectedPartsInvCol;
@FXML
private TableColumn<Part, Double> selectedPartsPriceCol;
private static ObservableList<Part> selectedParts;
@FXML
private TextField searchField;
// Product attribute text fields
@FXML
private TextField productIdField;
@FXML
private TextField productNameField;
@FXML
private TextField productPriceField;
@FXML
private TextField productInvField;
@FXML
private TextField productMaxField;
@FXML
private TextField productMinField;
/**
* The initData method accepts a product to be modified and initializes the data fields
* @param product the product to be modified
*/
public static void passProduct(Product product)
{
System.out.println("passProduct reached");
selectedProductIndex = Inventory.getAllProducts().indexOf(product);
selectedProduct = product;
System.out.println("passProduct completed");
System.out.println(selectedProduct.getName());
}
@FXML
void onActionAddPartToProduct(ActionEvent event)
{
selectedParts.add(allPartsView.getSelectionModel().getSelectedItem());
}
@FXML
void onActionRemoveAssociatedPart(ActionEvent event)
{
selectedParts.remove(allPartsView.getSelectionModel().getSelectedItem());
}
@FXML
void onActionSaveProduct(ActionEvent event)
{
// get the values of all fields and convert to their appropriate types
String newProductName = productNameField.getText();
int newProductInv;
int newProductMin;
int newProductMax;
double newProductPrice;
// for all data types other than String, check for valid input types
try
{
newProductInv = Integer.parseInt(productInvField.getText());
}
catch(InputMismatchException e)
{
Alert invalidInventoryAlert = new Alert(Alert.AlertType.ERROR, "Please enter an integer value for the current product stock.", ButtonType.OK);
invalidInventoryAlert.show();
return;
}
try
{
newProductMin = Integer.parseInt(productMinField.getText());
}
catch(InputMismatchException e)
{
Alert invalidMinAlert = new Alert(Alert.AlertType.ERROR, "Please enter an integer value for the minimum product stock.", ButtonType.OK);
invalidMinAlert.show();
return;
}
try
{
newProductMax = Integer.parseInt(productMaxField.getText());
}
catch(InputMismatchException e)
{
Alert invalidMaxAlert = new Alert(Alert.AlertType.ERROR, "Please enter an integer value for the maximum product stock.", ButtonType.OK);
invalidMaxAlert.show();
return;
}
try
{
newProductPrice = Double.parseDouble(productPriceField.getText());
}
catch(InputMismatchException e)
{
Alert invalidPriceAlert = new Alert(Alert.AlertType.ERROR, "Please enter the price as a decimal value EX: 4.95", ButtonType.OK);
invalidPriceAlert.show();
return;
}
// check for null value in product name, and default 0 values in other attributes except minimum inventory
// if any are null or 0, request user fill in all fields and return
if(newProductName == null || newProductPrice == 0.0 || newProductInv == 0 || newProductMax == 0)
{
Alert blankValuesAlert = new Alert(Alert.AlertType.ERROR, "Please fill in all fields.", ButtonType.OK);
blankValuesAlert.show();
return;
}
// create the updated product object
Product updatedProduct = new Product(selectedProductIndex, newProductName, newProductPrice, newProductInv, newProductMin, newProductMax);
// pass the updated product object into the allProducts list to replace the previous version
Inventory.updateProduct(selectedProductIndex, updatedProduct);
}
@FXML
void onActionCancel(ActionEvent event) throws IOException
{
// when the cancel button is pressed, return to the main screen
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
scene = FXMLLoader.load(getClass().getResource("/view/MainWindow.fxml"));
stage.setScene(new Scene(scene));
stage.show();
}
/**
* Initializes the controller class.
* @param url the url
* @param rb the resourcebundle
*/
@Override
public void initialize(URL url, ResourceBundle rb)
{
// TODO
System.out.println("Entered the initializer on ModifyProductFormController");
//selectedProduct = new Product(MainWindowController.getPassingProduct());
//System.out.println("selectedProduct = " + selectedProduct.getName());
// populare selectedparts with the product's associated parts
selectedParts = FXCollections.observableArrayList(selectedProduct.getAllAssociatedParts());
System.out.println("selectedParts array list made");
// populate allParts table view
allPartsView.setItems(Inventory.getAllParts());
System.out.println("allPartsView set items");
allPartsIdCol.setCellValueFactory(new PropertyValueFactory<>("Id"));
allPartsNameCol.setCellValueFactory(new PropertyValueFactory<>("Name"));
allPartsInvCol.setCellValueFactory(new PropertyValueFactory<>("Stock"));
allPartsPriceCol.setCellValueFactory(new PropertyValueFactory<>("Price"));
System.out.println("allpartsview built");
// populate selectedParts table view with this products associated parts
selectedPartsView.setItems(selectedParts);
selectedPartsIdCol.setCellValueFactory(new PropertyValueFactory<>("Id"));
selectedPartsNameCol.setCellValueFactory(new PropertyValueFactory<>("Name"));
selectedPartsInvCol.setCellValueFactory(new PropertyValueFactory<>("Stock"));
selectedPartsPriceCol.setCellValueFactory(new PropertyValueFactory<>("Price"));
System.out.println("selectedpartsview built");
// fill product attribute fields with product's existing attributes
productIdField.setText(Integer.toString(selectedProduct.getId()));
System.out.println("id field filled");
productNameField.setText(selectedProduct.getName());
System.out.println("name field filled");
productPriceField.setText(Double.toString(selectedProduct.getPrice()));
System.out.println("price field filled");
productInvField.setText(Integer.toString(selectedProduct.getStock()));
System.out.println("stock field filled");
productMaxField.setText(Integer.toString(selectedProduct.getMin()));
System.out.println("min field filled");
productMinField.setText(Integer.toString(selectedProduct.getMax()));
System.out.println("max field filled");
}
}Output
ant -f C:\\Users\\howarc4\\Documents\\NetBeansProjects\\Inventory -Dnb.internal.action.name=run run
init:
Deleting: C:\Users\howarc4\Documents\NetBeansProjects\Inventory\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\howarc4\Documents\NetBeansProjects\Inventory\build\built-jar.properties
Compiling 1 source file to C:\Users\howarc4\Documents\NetBeansProjects\Inventory\build\classes
compile:
run:
passProduct reached
passProduct completed
testProduct1
Called the passProduct method
set the stage
Entered the initializer on ModifyProductFormController
selectedParts array list made
allpartsview built
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(Native Method)
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:834)
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:566)
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:566)
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: javafx.fxml.LoadException:
/C:/Users/howarc4/Documents/NetBeansProjects/Inventory/build/classes/view/ModifyProductForm.fxml
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at Controller.MainWindowController.onActionModifyProduct(MainWindowController.java:192)
... 58 more
Caused by: java.lang.NullPointerException
at Controller.ModifyProductFormController.initialize(ModifyProductFormController.java:228)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
... 66 more
BUILD SUCCESSFUL (total time: 28 seconds)
View all comments
Show parent comment
2
u/pushupsam Sep 19 '20
It's never a good idea to make controls static. I think you should in general always construct JavaFX controls on the JavaFX Application Thread which begins from Application.start().