I play with Clojure (1.6) and JavaFX 8, and right at the beginning I ran into a problem. For example, this very simple code does not work:
(ns xxyyzz.core) (gen-class :name "xxyyzz.core.App" :extends javafx.application.Application :prefix "app-") (defn app-start [app stage] (let [button (javafx.scene.control.Button.)])) (defn launch [] (javafx.application.Application/launch xxyyzz.core.App (into-array String []))) (defn -main [] (launch))
This is the last part of the stack trace that seems relevant:
Caused by: java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:340) at clojure.lang.RT.classForName(RT.java:2070) at clojure.lang.Compiler$HostExpr.maybeClass(Compiler.java:969) at clojure.lang.Compiler$HostExpr.access$400(Compiler.java:747) at clojure.lang.Compiler$NewExpr$Parser.parse(Compiler.java:2494) at clojure.lang.Compiler.analyzeSeq(Compiler.java:6560) ... 48 more Caused by: java.lang.IllegalStateException: Toolkit not initialized at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:276) at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:271) at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:562) at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:524) at javafx.scene.control.Control.<clinit>(Control.java:81) ... 55 more
I donβt speak Java at all, but by researching this, it seems that the problem is with Clojure and the way to import Java classes. If I understood correctly, during import it starts the static class initializer and for some JavaFX classes ( Button in my case), which fails.
Guess I have two questions: do I understand this error correctly? And secondly, is there any way around this problem? I tried pulling out the import inside functions instead of declaration (ns), but it still doesn't work.
If there is no Clojure fix, is this fix possible with some additional Java code?
Any tips and pointers are welcome!
source share