AutoCompletionBinding无法访问类com.sun.javafx.event.EventHandlerManager

sigwle7e  于 2024-01-05  发布在  Java
关注(0)|答案(2)|浏览(248)

我有一些问题与javafxorg.controlsfx.control.textfield.TextFields。我试图实现一个功能,将获得可能的用户输入预测从数据库,使用户只能选择“授权”选项。而与controlsfx工作时,我遇到了这个错误。
错误:

  1. 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
  2. at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:521)
  3. at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107)
  4. at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:92)
  5. at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:187)
  6. at sample.Controller.lambda$listenKey$0(Controller.java:40)
  7. at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
  8. at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
  9. at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
  10. at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
  11. at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
  12. at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  13. at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  14. at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  15. at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  16. at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  17. at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
  18. at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
  19. at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
  20. at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
  21. at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
  22. at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
  23. at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
  24. at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
  25. at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
  26. at java.base/java.security.AccessController.doPrivileged(Native Method)
  27. at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
  28. at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
  29. at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
  30. at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
  31. at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
  32. at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  33. at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
  34. at java.base/java.lang.Thread.run(Thread.java:834)

字符串
我已经学会了,引用Since Java Web Start is no longer a part of Java SE 11 and later, we will not look into this.。我不知道是因为那个还是我做错了什么。
下面是我的代码:

  1. package sample;
  2. /**
  3. * Sample Skeleton for 'sample.fxml' Controller Class
  4. */
  5. import java.net.URL;
  6. import java.util.*;
  7. import javafx.fxml.FXML;
  8. import javafx.scene.control.TextField;
  9. import org.controlsfx.control.textfield.TextFields;
  10. public class Controller{
  11. @FXML // ResourceBundle that was given to the FXMLLoader
  12. private ResourceBundle resources;
  13. @FXML // URL location of the FXML file that was given to the FXMLLoader
  14. private URL location;
  15. // fx:id="inputAutoComplete";
  16. @FXML
  17. private TextField inputAutoComplete;
  18. @FXML // This method is called by the FXMLLoader when initialization is complete
  19. void initialize() {
  20. System.out.println("XD");
  21. listenKey();
  22. }
  23. ArrayList<String> possibleWordSet = new ArrayList<>();
  24. public void listenKey(){
  25. databaseConnection dbconn = new databaseConnection();
  26. inputAutoComplete.setOnKeyPressed((event) -> {
  27. if(inputAutoComplete.getText().length() > 4){
  28. System.out.println(inputAutoComplete.getText());
  29. possibleWordSet = dbconn.getSuggestedData(inputAutoComplete.getText());
  30. System.out.println(possibleWordSet);
  31. TextFields.bindAutoCompletion(inputAutoComplete,possibleWordSet);
  32. }
  33. });
  34. }
  35. }


有没有人给予我一些如何实现这个功能的例子,或者只是告诉我做错了什么?

4c8rllxm

4c8rllxm1#

如果您使用的是ControlsFX 11,请将以下VM选项添加到运行时命令行:

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

字符串
注:以前的答案(在其他网站上,也在这里SO)建议如下:

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


然而,ControlFX的最新版本似乎是模块化的,模块不再是未命名的。如果您使用的是以前的版本(例如版本9),请使用命令行选项的ALL-UNNAMED变体。

ncgqoxb0

ncgqoxb02#

如果你在这里结束并使用maven插件(javafx:run)来运行你的应用,你可以使用以下配置来运行它。

  1. <plugin>
  2. <groupId>org.openjfx</groupId>
  3. <artifactId>javafx-maven-plugin</artifactId>
  4. <version>0.0.4</version>
  5. <configuration>
  6. <mainClass>some.package.App</mainClass>
  7. <options>
  8. <option>--add-exports</option>
  9. <option>javafx.base/com.sun.javafx.event=org.controlsfx.controls</option>
  10. </options>
  11. </configuration>
  12. </plugin>

字符串

相关问题