Autocomplete in Javafx11.0.2 not working shows error of javafx.base and controlsfx not exported

628 views Asked by At

I am using javafx-11.0.2 and trying to use autocomplete feature.The code is like this:

@FXML private TextField corporateName;
    private Set<String> possibleSuggestion = new HashSet<>(Arrays.asList(_possibleSuggestion));
private String[] _possibleSuggestion ={"Abc Corp", "bbb corp", "jags corp", "test","xuz","hyatt","yak n yeti"};
    

public void initialize(URL location, ResourceBundle resources) {
       
        TextFields.bindAutoCompletion(corporateName,possibleSuggestion);
}

And the VM options is as follows:

--module-path /home/development/javafx-sdk-11.0.2/lib$Classpath$ 
--add-modules javafx.controls,javafx.fxml,javafx.base
--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED

but everytime it is showing error like this :

Caused by: java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in module controlsfx) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to module controlsfx

How can I resolve this error ? Please suggest.

2

There are 2 answers

0
BalGu On

Your issues is that --add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED works only for JavaFX 9 or less.

This is the option you want to use in your VM options.

--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls

0
Rashid Makki On

Please refer to the following link in order to solve this issue: https://dzone.com/articles/how-to-export-all-modules-to-all-modules-at-runtime-in-java

Add the dependency in your project :

      <dependency>
        <groupId>org.burningwave</groupId>
        <artifactId>core</artifactId>
        <version>12.62.7</version>
     </dependency>

Add the following in module-info.java file:

 requires org.burningwave.core;

Execute this method after adding the dependency:

 Modules.exportAllToAll();