I could include the controlsfx into my project in IntelliJ but I can't run the program.
I also already try the other solution: adding this into VM options
我可以将controlsfx包含到我的IntelliJ项目中,但我无法运行该程序。我也已经尝试了另一种解决方案:将其添加到VM选项中
--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls
When I run the program, it has run time error:
当我运行该程序时,它出现运行时错误:
WARNING: Unknown module: org.controlsfx.controls specified to --add-exports
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:72)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at [email protected]/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:270)
at [email protected]/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
at [email protected]/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1853)
... 33 more
Caused by: java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x6bbb636e) 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 @0x6bbb636e
at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:538)
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:188)
at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:182)
at Controller.HomeSubScene.SearchBookingController.setUp(SearchBookingController.java:44)
at Controller.HomeCustController.showScene(HomeCustController.java:162)
at Controller.HomeCustController.showManageBookingScene(HomeCustController.java:134)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 40 more
I hope I could use the controls fx in my project.
更多回答
优秀答案推荐
It looks like org.controlsfx.controls
is being put onto the class path instead of the module path by IntelliJ:
看起来像是IntelliJ将org.Controsfx.Controls放到了类路径而不是模块路径上:
class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x6bbb636e)
(The unnamed modules means the class path).
(未命名的模块表示类路径)。
IntelliJ puts dependencies on the class or module path depending on whether the project itself is modular. So, in order to have IJ put org.controlsfx.controls
on the module path, you have to modularise the project by adding a module-info.java
file.
IntelliJ根据项目本身是否是模块化的,将依赖项放在类或模块路径上。因此,为了让IJ将org.controlsfx.controls放在模块路径上,您必须通过添加module-info.java文件来模块化项目。
(see also: IntelliJ: Put some dependencies on the module path in non-modular application)
(另见:IntelliJ:在非模块化应用程序中的模块路径上放置一些依赖项)
If you don't want to modularise your project, alternatively you could try using:
如果您不想模块化您的项目,或者您可以尝试使用:
--add-exports=javafx.base/com.sun.javafx.event=All-UNNAMED
Which exports the package to the class path instead (unnamed module). However, this might not work if org.controlsfx.controls
does not support being put on the class path.
它将包导出到类路径(未命名模块)。但是,如果org.Controsfx.Controls不支持放在类路径上,则这可能不起作用。
更多回答
Thanks for ur answer. After I replace the vm options with this --add-exports=javafx.base/com.sun.javafx.event=All-UNNAMED. I able to run the program, it does not have any run time error. But the TextFields.bindAutoCompletion() is not working.
谢谢你的回答。在我用此--add-exports=javafx.base/com.sun.javafx.event=All-UNNAMED.替换了VM选项之后我能够运行这个程序,它没有任何运行时的错误。但TextFields.bindAutoCompletion()不起作用。
Well as noted in the answer: “ However, this might not work if org.controlsfx.controls does not support being put on the class path.” So try making your app modular (adding a module-info) instead, as also noted in the answer. There is documentation on the controlsfx site about using it in a modular environment.
正如答案中所指出的:“然而,如果org.Controsfx.Controls不支持放在类路径上,则这可能不起作用。”因此,请尝试使您的应用程序模块化(添加一个模块信息),如答案中所述。Controsfx站点上有关于在模块化环境中使用它的文档。
我是一名优秀的程序员,十分优秀!