FXML file location is not found and the URL always returns null in a JavaFX application

I am creating a JavaFX GUI application using IntelliJ, with the project being built with Maven. I have recently been attempting to create a function to switch between two scenes upon the click of a button. The Java code for the function is as follows:

public void showNewSetPage() {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("newSetPage.fxml"));
        Scene scene = null;

        try {
            scene = new Scene(loader.load());
        } catch (Exception e) {
            e.printStackTrace();
        }

        Stage stage = new Stage();
        stage.setScene(scene);
            
        stage.show();

    }

Upon running this code however, it returns this error: java.lang.IllegalStateException: Location is not set. It also states that the problem in the line scene = new Scene(loader.load());.

Below is a screenshot of how I have organized my files:

File structure

The function showNewSetPage() belongs to the homePageController class.

Here is a link to a Google Drive folder which contains all the project source code files:
https://drive.google.com/drive/folders/1RftQHI-NVT3cfBnlzfFclkHB3IJflp8H?usp=drive_link

I know that this is a common problem that many other people have faced when trying to create a function to switch scenes in JavaFX. So far to solve the problem, I have only tried solutions related to changing the string that is inserted into the getResource() function to be used as a URL for the load() function.

In the code that I pasted above, I have written FXML file location as “newSetPage.fxml”, however I have also tried:

“/newSetPage.fxml” — (adding a preceding forward slash)

“/Users/damondsylva/Desktop/Coding Projects/Java/CompSci IA Flashcards App/src/main/resources/org/example/compsci_ia_flashcards_app/newSetPage.fxml” — (absolute path)

“src/main/resources/org/example/compsci_ia_flashcards_app/newSetPage.fxml” — (content root)

“org/example/compsci_ia_flashcards_app/newSetPage.fxml” — (source root)

However, all of these strings have pointed to null locations.

I think the problem may be related to the way my project files are structured with Maven, and that I may have to change something in the pom.xml file, but have not been able to understand how it works fully and I’m scared to change anything in that file in fear of creating a bigger problem. All the solutions that I have looked at so far have always cited something about changing the structure of location/URL strings (e.g: adding a preceding forward slash), but as I mentioned before, none of those changes worked.

New contributor

DAMONster 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