javavalidationjavafxcontrolsfxmodule-info

Error in module system when registering controlsFX validator for combo box in JavaFX project


I'm trying to register ControlsFX validator for a ComboBox in JavaFX. Then, I got the below error relating to the module system. When I try to open javafx.scene package to the org.controlsfx.controls module, it also resulted in an error. I'll add all the codes and errors I got below.

This is my code which is causing the error.

ValidationSupport validationSupport = new ValidationSupport();
validationSupport.registerValidator(prefixCombo, Validator.createEmptyValidator("Combobox selection required!"));

This is the error I got when running the project.

Exception in thread "JavaFX Application Thread" java.lang.reflect.InaccessibleObjectException: Unable to make protected javafx.collections.ObservableList javafx.scene.Parent.getChildren() accessible: module javafx.graphics does not "opens javafx.scene" to module org.controlsfx.controls
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)

This is my current module-info.java file

module system {
    requires javafx.controls;
    requires javafx.fxml;
    requires jakarta.persistence;
    requires org.hibernate.orm.core;
    requires MaterialFX;
    requires org.slf4j;
    requires de.jensd.fx.glyphs.fontawesome;
    requires static lombok;
    requires org.controlsfx.controls;
    requires javafx.graphics;


    opens com.example.system to javafx.fxml, org.controlsfx.controls;
    exports com.example.system;
    exports com.example.system.controller;
    opens com.example.system.controller to javafx.fxml, javafx.graphics;
    opens com.example.system.entity to org.hibernate.orm.core;
    opens com.example.system.tm to javafx.base;
}

I tried adding opens javafx.scene to org.controlsfx.controls; to module-infor.java. Then, resulted in another error Package not found: javafx.scene

Thank you all in advance!!


Solution

  • Using an opens directive in the module-info pertains to opening a package of the module system(your module) to another module specified i.e org.controlsfx.controls. Hence, the expected compilation error, since your application module doesn't include the package mentioned.

    What you are looking for is the command line argument that could help you provide access to javafx.scene package from module javafx.graphics for your runtime option i.e.

    --add-opens javafx.graphics/javafx.scene=org.controlsfx.controls
    

    Note - Keep in mind this shall only be considered a workaround.