0

I have a JavaFX program that I need to make executable. I'm currently trying to do it with IntelliJ IDEA, it does create the .jar, but when I try to click on a clickable item that should pop a window it doesn't and instead in the console it prints this error:

Screenshot of the error I get

If it can be helpful this is a screenshot of the internal structure of the project + whats inside the manifest

I should also specify that I imported the javaFX library in Project Structure -> Artifacts.

(I already made a .jar executable for another project and worked fine there, but it didn't had any pop-up windows nor multiple .fxml / controllers... so I think that might be whats making it crash, but I'm not sure)

Edit: Also I forgot to say that the problem i reported above only happens in the .jar, if i debug the program/run it through the IDE it works perfectly fine.

Edit (Error code copy-pasted):

    Dec 30, 2021 6:51:43 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 16 by JavaFX runtime of version 11.0.2
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
        at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3564)
        at javafx.scene.Scene$ClickGenerator.access$8200(Scene.java:3492)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3860)
        at javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
        at javafx.scene.Scene.processMouseEvent(Scene.java:1849)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:556)
        at com.sun.glass.ui.View.notifyMouse(View.java:942)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
        at com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
        at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1782)
        ... 31 more
Caused by: java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
        at Controllers.Home.LWELencoClick(Home.java:521)
        ... 43 more
Code-Dani
  • 43
  • 6
  • Don't screenshot error messages, instead put the error messages as text in the question formatted as code (indent 4 spaces). Please fix this. – jewelsea Dec 29 '21 at 22:47
  • Use a build tool (maven) with the maven standard directory layout structure (google it). Create a new project using the [Idea New JavaFX Project wizard](https://www.jetbrains.com/help/idea/javafx.html) and move your code to the relevant locations in your new project. Then follow instructions at [Maven Shade JavaFX runtime components are missing](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing), being aware that an executable jar for JavaFX is an unsupported configuration. Use Maven to generate the jars, not the Idea artifact system. – jewelsea Dec 29 '21 at 23:12
  • Location is not set error means that an fxml resource could not be found, trouble shooting for that is: [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other) – jewelsea Dec 29 '21 at 23:16
  • @jewelsea Hello, I updated the question as you suggested with the copy-pasted error message formatted as code. Also I'm going to try what you suggested, thanks – Code-Dani Dec 30 '21 at 17:56
  • @jewelsea Thanks, I fixed, the problem was a path that had " .. " in at the start – Code-Dani Dec 30 '21 at 21:17

1 Answers1

1

I solved it. The error was that I had a ".." at the start of a path that was pointing towards the FXML. So the IDE was all ok with that, but the .jar works differently so it was throwing errors for the path.

this is the line that was giving the error

fxmlLoader = new FXMLLoader(getClass().getResource("../FXML/CentroVaccinaleRG.fxml"));

this is how I modified it

fxmlLoader = new FXMLLoader(getClass().getResource("/FXML/CentroVaccinaleRG.fxml"));
Code-Dani
  • 43
  • 6