CodexBloom - Programming Q&A Platform

Eclipse 2023-09: Problems with JavaFX Scene Builder Integration in a Modular Project

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
javafx eclipse scene-builder modular Java

I've been struggling with this for a few days now and could really use some help... I'm sure I'm missing something obvious here, but I'm struggling to integrate JavaFX Scene Builder with my modular Java application in Eclipse 2023-09. I have set up a modular project with a proper `module-info.java`, but when I try to open a FXML file in Scene Builder, it doesn't recognize the custom controllers I have defined. Instead, I get the following behavior in Scene Builder: `java.lang.NullPointerException: want to invoke 'javafx.fxml.FXMLLoader.setControllerFactory(javafx.util.Callback)' because 'this.fXMLLoader' is null`. Here's a simplified version of my `module-info.java`: ```java module my.module { requires javafx.controls; requires javafx.fxml; opens my.module.controllers to javafx.fxml; } ``` AND in my controller class, I have: ```java package my.module.controllers; import javafx.fxml.FXML; import javafx.scene.control.Button; public class SampleController { @FXML private Button myButton; @FXML public void initialize() { myButton.setText("Click Me!"); } } ``` I've ensured that the FXML file references the controller correctly using the `fx:controller` attribute: ```xml <?xml version="1.0" encoding="UTF-8"?> <?import my.module.controllers.SampleController?> <AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="my.module.controllers.SampleController"> <Button fx:id="myButton" text="Press" /> </AnchorPane> ``` I've double-checked the package names and paths, but Scene Builder still fails to recognize the controller. I've also tried cleaning and rebuilding the project in Eclipse, but that didn't resolve the scenario. Does anyone have insights into what might be going wrong with this integration or how to properly set up JavaFX in a modular project within Eclipse? This is part of a larger application I'm building. What's the best practice here? My development environment is Linux. Am I missing something obvious? This is part of a larger API I'm building. Any ideas what could be causing this?