Wojciech Miśta
Wojciech Miśta

Reputation: 85

AutoCompletionBinding cannot access class com.sun.javafx.event.EventHandlerManager

I have some issues with javafx and org.controlsfx.control.textfield.TextFields. I'm trying to implement a feature that would get possible user input predictions from a database so that user can only pick the "authorized" options. While working with controlsfx I came across this error.

Error:

Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x239a4ba) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to unnamed module @0x239a4ba
at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:521)
at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107)
at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:92)
at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:187)
at sample.Controller.lambda$listenKey$0(Controller.java:40)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

I've learnt that, quote Since Java Web Start is no longer a part of Java SE 11 and later, we will not look into this.. I don't know if it's because of that or I'm doing something wrong.

Here's my code:

    package sample;
/**
 * Sample Skeleton for 'sample.fxml' Controller Class
 */

import java.net.URL;
import java.util.*;

import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import org.controlsfx.control.textfield.TextFields;

public class Controller{

    @FXML // ResourceBundle that was given to the FXMLLoader
    private ResourceBundle resources;

    @FXML // URL location of the FXML file that was given to the FXMLLoader
    private URL location;

    // fx:id="inputAutoComplete";
    @FXML
    private TextField inputAutoComplete;

    @FXML // This method is called by the FXMLLoader when initialization is complete
    void initialize() {
        System.out.println("XD");
        listenKey();
    }

    ArrayList<String> possibleWordSet = new ArrayList<>();

    public void listenKey(){
        databaseConnection dbconn = new databaseConnection();
        inputAutoComplete.setOnKeyPressed((event) -> {
            if(inputAutoComplete.getText().length() > 4){
                System.out.println(inputAutoComplete.getText());
                possibleWordSet = dbconn.getSuggestedData(inputAutoComplete.getText());
                System.out.println(possibleWordSet);
                TextFields.bindAutoCompletion(inputAutoComplete,possibleWordSet);
            }
        });
    }
}

Can someone give me some examples of how to implement this feature or just tell what am I doing wrong?

Upvotes: 8

Views: 7166

Answers (2)

WizardsOfWor
WizardsOfWor

Reputation: 3144

If you ended up here and are using the maven plugin (javafx:run) to run your app, you can use the following configuration to get it running.

        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.4</version>
            <configuration>
                <mainClass>some.package.App</mainClass>
                 <options>
                    <option>--add-exports</option>
                    <option>javafx.base/com.sun.javafx.event=org.controlsfx.controls</option>
                 </options>
            </configuration>
        </plugin>

Upvotes: 5

Barry Brown
Barry Brown

Reputation: 20624

If you are using ControlsFX 11, add the following VM option to your runtime command line:

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

Note: Previous answers (on other sites and also here on SO) have suggested the following:

--add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED

However, recent versions of ControlFX appear to be modularized and the modules are no longer unnamed. If you are using a previous version (say, version 9), use the ALL-UNNAMED variant of the command line option.

Upvotes: 9

Related Questions