JavaFX Application Fails to Load FXML File with IllegalStateException: Location is not set

I am developing a JavaFX application using Maven in IntelliJ IDEA. My application fails to load the FXML file and throws the following exception:

C:UsersBruce.jdksopenjdk-22.0.1binjava.exe "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2024.1libidea_rt.jar=22421:C:Program FilesJetBrainsIntelliJ IDEA 2024.1bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:UsersBruce.m2repositoryorgopenjfxjavafx-controls22-ea+11javafx-controls-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-graphics22-ea+11javafx-graphics-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-base22-ea+11javafx-base-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-fxml22-ea+11javafx-fxml-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-web22-ea+11javafx-web-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-media22-ea+11javafx-media-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-swing22-ea+11javafx-swing-22-ea+11.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-swing22-ea+11javafx-swing-22-ea+11-win.jar;C:UsersBruce.m2repositoryorgpostgresqlpostgresql42.7.3postgresql-42.7.3.jar;C:UsersBruce.m2repositoryorgcheckerframeworkchecker-qual3.42.0checker-qual-3.42.0.jar -p C:UsersBruce.m2repositoryorgcontrolsfxcontrolsfx11.1.2controlsfx-11.1.2.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-media22-ea+11javafx-media-22-ea+11-win.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-base22-ea+11javafx-base-22-ea+11-win.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-web22-ea+11javafx-web-22-ea+11-win.jar;C:UsersBruce.m2repositoryorgkordampikonliikonli-core12.3.1ikonli-core-12.3.1.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-fxml22-ea+11javafx-fxml-22-ea+11-win.jar;C:UsersBruce.m2repositorynetsynedravalidatorfx.4.0validatorfx-0.4.0.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-graphics22-ea+11javafx-graphics-22-ea+11-win.jar;C:UsersBruceDesktopPharmacyManagementSystem_v1.0.1targetclasses;C:UsersBruce.m2repositoryorgkordampikonliikonli-javafx12.3.1ikonli-javafx-12.3.1.jar;C:UsersBruce.m2repositoryorgopenjfxjavafx-controls22-ea+11javafx-controls-22-ea+11-win.jar;C:UsersBruce.m2repositoryeuhansolotilesfx11.48tilesfx-11.48.jar -m trojanlabs.pharmacymanagementsystemv/trojanlabs.pharmacymanagementsystem.PharmacyManagementSystem Exception in Application start method java.lang.reflect.InvocationTargetException  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)    at java.base/java.lang.reflect.Method.invoke(Method.java:580)   at javafx.graphics@22-ea/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)   at javafx.graphics@22-ea/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)   at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)    at java.base/java.lang.reflect.Method.invoke(Method.java:580)   at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1147) Caused by: java.lang.RuntimeException: Exception in Application start method   at javafx.graphics@22-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)  at javafx.graphics@22-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)  at java.base/java.lang.Thread.run(Thread.java:1570) Caused by: javafx.fxml.LoadException:  /C:/Users/Bruce/Desktop/PharmacyManagementSystem_v1.0.1/target/classes/trojanlabs/pharmacymanagementsystem/hello-view.fxml:84    at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2727)    at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2705)  at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2568)  at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2536)  at trojanlabs.pharmacymanagementsystemv/trojanlabs.pharmacymanagementsystem.PharmacyManagementSystem.start(PharmacyManagementSystem.java:13)    at javafx.graphics@22-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)     at javafx.graphics@22-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)    at javafx.graphics@22-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)  at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)     at javafx.graphics@22-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)  at javafx.graphics@22-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)   at javafx.graphics@22-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)    at javafx.graphics@22-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)  ... 1 more Caused by: java.lang.IllegalArgumentException: Unable to coerce 10 to class javafx.geometry.Insets.  at javafx.fxml@22-ea/com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:497)   at javafx.fxml@22-ea/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:259)  at javafx.fxml@22-ea/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)   at javafx.fxml@22-ea/javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:525)  at javafx.fxml@22-ea/javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:375)   at javafx.fxml@22-ea/javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:337)   at javafx.fxml@22-ea/javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:248)  at javafx.fxml@22-ea/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:780)     at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2974)     at javafx.fxml@22-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2659)  ... 12 more Exception running application trojanlabs.pharmacymanagementsystem.PharmacyManagementSystem  Process finished with exit code 1     

Here’s my PharmacyManagementSystem class:

package trojanlabs.pharmacymanagementsystem;

//import com.sun.tools.javac.Main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class PharmacyManagementSystem extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(PharmacyManagementSystem.class.getResource("/trojanlabs/pharmacymanagementsystem/hello-view.fxml"));
        Scene scene = new Scene(loader.load());
        primaryStage.setScene(scene);
        primaryStage.setTitle("Pharmacy Management System");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Here’s my PharmacyController class:

package trojanlabs.pharmacymanagementsystem;

import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;


import java.util.Date;
import java.util.List;

public class PharmacyController {
    private final PharmacyService pharmacyService;

    // Drug fields
    @FXML
    private TextField drugCodeField;
    @FXML
    private TextField drugNameField;
    @FXML
    private TextField drugPriceField;
    @FXML
    private TextField supplierCodeFieldForDrug; // Changed variable name to avoid conflict
    @FXML
    private TextField drugStockField;
    @FXML
    private TableView<Drug> drugTable;
    @FXML
    private TableColumn<Drug, String> drugCodeColumn;
    @FXML
    private TableColumn<Drug, String> drugNameColumn;
    @FXML
    private TableColumn<Drug, Double> drugPriceColumn;
    @FXML
    private TableColumn<Drug, String> drugSupplierColumn;
    @FXML
    private TableColumn<Drug, Integer> drugStockColumn;

    // Supplier fields
    @FXML
    private TextField supplierCodeField;
    @FXML
    private TextField supplierNameField;
    @FXML
    private TextField supplierLocationField;
    @FXML
    private TableView<Supplier> supplierTable;
    @FXML
    private TableColumn<Supplier, String> supplierCodeColumn;
    @FXML
    private TableColumn<Supplier, String> supplierNameColumn;
    @FXML
    private TableColumn<Supplier, String> supplierLocationColumn;

    // Customer fields
    @FXML
    private TextField customerIdField;
    @FXML
    private TextField customerNameField;
    @FXML
    private TextField customerContactField;
    @FXML
    private TableView<Customer> customerTable;
    @FXML
    private TableColumn<Customer, String> customerIdColumn;
    @FXML
    private TableColumn<Customer, String> customerNameColumn;
    @FXML
    private TableColumn<Customer, String> customerContactColumn;

    // Sale fields
    @FXML
    private TableView<Sale> saleTable;
    @FXML
    private TableColumn<Sale, Integer> saleIdColumn;
    @FXML
    private TableColumn<Sale, String> saleDrugColumn;
    @FXML
    private TableColumn<Sale, Integer> saleQuantityColumn;
    @FXML
    private TableColumn<Sale, String> saleBuyerColumn;
    @FXML
    private TableColumn<Sale, Date> saleDateColumn;

    public PharmacyController() {
        pharmacyService = new PharmacyService();
    }

    @FXML
    public void initialize() {
        drugCodeColumn.setCellValueFactory(new PropertyValueFactory<>("code"));
        drugNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        drugPriceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
        drugSupplierColumn.setCellValueFactory(cellData -> cellData.getValue().supplierProperty().get().nameProperty());
        drugStockColumn.setCellValueFactory(new PropertyValueFactory<>("stock"));
        loadDrugData();

        supplierCodeColumn.setCellValueFactory(new PropertyValueFactory<>("code"));
        supplierNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        supplierLocationColumn.setCellValueFactory(new PropertyValueFactory<>("location"));
        loadSupplierData();

        customerIdColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
        customerNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        customerContactColumn.setCellValueFactory(new PropertyValueFactory<>("contact"));
        loadCustomerData();

        saleIdColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
        saleDrugColumn.setCellValueFactory(cellData -> cellData.getValue().drugProperty().get().nameProperty());
        saleQuantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity"));
        saleBuyerColumn.setCellValueFactory(new PropertyValueFactory<>("buyer"));
        saleDateColumn.setCellValueFactory(new PropertyValueFactory<>("date"));
        loadSaleData();
    }

    @FXML
    private void handleAddDrug() {
        String drugCode = drugCodeField.getText();
        String name = drugNameField.getText();
        double price = Double.parseDouble(drugPriceField.getText());
        String supplierCode = supplierCodeFieldForDrug.getText();
        int stock = Integer.parseInt(drugStockField.getText());

        Supplier supplier = pharmacyService.searchSupplier(supplierCode);
        if (supplier != null) {
            Drug drug = new Drug(drugCode, name, price, supplier, stock);
            pharmacyService.addDrug(drug);
            loadDrugData();
        } else {
            // Handle supplier not found
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText("Supplier Not Found");
            alert.setContentText("Supplier with code " + supplierCode + " does not exist.");
            alert.showAndWait();
        }
    }

    @FXML
    private void handleAddSupplier() {
        String supplierCode = supplierCodeField.getText();
        String name = supplierNameField.getText();
        String location = supplierLocationField.getText();

        Supplier supplier = new Supplier(supplierCode, name, location);
        pharmacyService.addSupplier(supplier);
        loadSupplierData();
    }

    @FXML
    private void handleAddCustomer() {
        String customerId = customerIdField.getText();
        String name = customerNameField.getText();
        String contact = customerContactField.getText();

        Customer customer = new Customer(customerId, name, contact);
        pharmacyService.addCustomer(customer);
        loadCustomerData();
    }

    private void loadDrugData() {
        List<Drug> drugs = pharmacyService.viewAllDrugs();
        drugTable.getItems().setAll(drugs);
    }

    private void loadSupplierData() {
        List<Supplier> suppliers = pharmacyService.viewAllSuppliers();
        supplierTable.getItems().setAll(suppliers);
    }

    private void loadCustomerData() {
        List<Customer> customers = pharmacyService.viewAllCustomers();
        customerTable.getItems().setAll(customers);
    }

    private void loadSaleData() {
        List<Sale> sales = pharmacyService.viewAllSales();
        saleTable.getItems().setAll(sales);
    }

    @FXML
    private void handleGenerateReport() {
        pharmacyService.generateReport();
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Report");
        alert.setHeaderText("Report Generated");
        alert.setContentText("Report has been generated successfully.");
        alert.showAndWait();
    }
}

And here’s my hello-view.fxml file:

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="trojanlabs.pharmacymanagementsystem.PharmacyController" spacing="10" padding="10">
    <Label text="Pharmacy Management System" style="-fx-font-size: 16px; -fx-font-weight: bold;"/>

    <!-- Drugs Management -->
    <Label text="Drugs Management" style="-fx-font-size: 14px; -fx-font-weight: bold;"/>
    <GridPane hgap="10" vgap="10">
        <Label text="Drug Code:"/>
        <TextField fx:id="drugCodeField"/>
        <Label text="Name:"/>
        <TextField fx:id="drugNameField"/>
        <Label text="Price:"/>
        <TextField fx:id="drugPriceField"/>
        <Label text="Supplier Code:"/>
        <TextField fx:id="supplierCodeField"/>
        <Label text="Stock:"/>
        <TextField fx:id="drugStockField"/>
        <Button text="Add Drug" onAction="#handleAddDrug"/>
    </GridPane>
    <TableView fx:id="drugTable">
        <TableColumn text="Code" fx:id="drugCodeColumn"/>
        <TableColumn text="Name" fx:id="drugNameColumn"/>
        <TableColumn text="Price" fx:id="drugPriceColumn"/>
        <TableColumn text="Supplier" fx:id="drugSupplierColumn"/>
        <TableColumn text="Stock" fx:id="drugStockColumn"/>
    </TableView>

    <!-- Suppliers Management -->
    <Label text="Suppliers Management" style="-fx-font-size: 14px; -fx-font-weight: bold;"/>
    <GridPane hgap="10" vgap="10">
        <Label text="Supplier Code:"/>
        <TextField fx:id="supplierCodeFieldForDrug"/>
        <Label text="Name:"/>
        <TextField fx:id="supplierNameField"/>
        <Label text="Location:"/>
        <TextField fx:id="supplierLocationField"/>
        <Button text="Add Supplier" onAction="#handleAddSupplier"/>
    </GridPane>
    <TableView fx:id="supplierTable">
        <TableColumn text="Code" fx:id="supplierCodeColumn"/>
        <TableColumn text="Name" fx:id="supplierNameColumn"/>
        <TableColumn text="Location" fx:id="supplierLocationColumn"/>
    </TableView>

    <!-- Customers Management -->
    <Label text="Customers Management" style="-fx-font-size: 14px; -fx-font-weight: bold;"/>
    <GridPane hgap="10" vgap="10">
        <Label text="Customer ID:"/>
        <TextField fx:id="customerIdField"/>
        <Label text="Name:"/>
        <TextField fx:id="customerNameField"/>
        <Label text="Contact:"/>
        <TextField fx:id="customerContactField"/>
        <Button text="Add Customer" onAction="#handleAddCustomer"/>
    </GridPane>
    <TableView fx:id="customerTable">
        <TableColumn text="ID" fx:id="customerIdColumn"/>
        <TableColumn text="Name" fx:id="customerNameColumn"/>
        <TableColumn text="Contact" fx:id="customerContactColumn"/>
    </TableView>

    <!-- Sales Management -->
    <Label text="Sales Management" style="-fx-font-size: 14px; -fx-font-weight: bold;"/>
    <TableView fx:id="saleTable">
        <TableColumn text="ID" fx:id="saleIdColumn"/>
        <TableColumn text="Drug" fx:id="saleDrugColumn"/>
        <TableColumn text="Quantity" fx:id="saleQuantityColumn"/>
        <TableColumn text="Buyer" fx:id="saleBuyerColumn"/>
        <TableColumn text="Date" fx:id="saleDateColumn"/>
    </TableView>

    <!-- Report Generation -->
    <Button text="Generate Report" onAction="#handleGenerateReport"/>
</VBox>

I have verified the file paths and class names, but the issue persists. What might be causing the java.lang.IllegalStateException: Location is not set error, and how can I fix it?

New contributor

Solomon Bruce-Lafia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật