0

I'm working on a JavaFX project using NetBeans, and I've encountered an issue with loading an FXML file. Originally, my VentanaLogin.fxml file was in the practica6.main package, but I moved it to a new package practica6.vista to better organize the project.

Updating property file: C:\Users\Usuario\Documents\NetBeansProjects\Practica6_Parte3\build\built-jar.properties
Compiling 1 source file to C:\Users\Usuario\Documents\NetBeansProjects\Practica6_Parte3\build\classes
compile-single:
run-single:
Exception in Application start method
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:569)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    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:569)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1091)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3374)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3337)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3305)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3277)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3246)
    at practica6.main.main.start(main.java:37)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    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:184)
    ... 1 more
Exception running application practica6.main.main
C:\Users\Usuario\Documents\NetBeansProjects\Practica6_Parte3\nbproject\build-impl.xml:1367: The following error occurred while executing this line:
C:\Users\Usuario\Documents\NetBeansProjects\Practica6_Parte3\nbproject\build-impl.xml:962: Java returned: 1
BUILD FAILED (total time: 2 seconds)

The FXML file is located at src/practica6/vista/VentanaLogin.fxml.

In my Main class, I load the FXML like this:

FXMLLoader.load(getClass().getResource("/practica6/vista/VentanaLogin.fxml"));

This is the general structure on my packages

enter image description here

However, the program still fails to load the FXML file. I have tried cleaning and rebuilding the project, but the issue persists. Does anyone know what could be causing this error or what I may have missed when moving the FXML file to a new package?

4
  • There are already many similar questions to yours on SO that have answers. Did you search? Note that the FXML file should not be in the src folder, it should be together with all the compiled Java classes, i.e. files with the .class extension. I don't use NetBeans, I use Eclipse and as part of the build process (not Maven), Eclipse copies resource folders to the build destination folder. Commented Nov 10, 2024 at 12:52
  • Read stackoverflow.com/questions/61531317/…, particularly the “troubleshooting” section. What’s important is what’s in the build/output folder and that’s determined in part by your build configuration. Commented Nov 10, 2024 at 17:39
  • The NetBeans project cited here uses the standard layout discussed by @James_D. Commented Nov 10, 2024 at 18:05
  • 1
    I would suggest you go to your folder and remove the problem files to a new location outside of your project. Then, use ideas from [stackoverflow.com/a/41707187/2423906](here) to create and place your new files in the correct package/location. Then, carefully copy the code from the previously moved files to the newly created files. You will have to pay attention to the FXML copy so that you don't overwrite fx:controller="...". So, basically, you want to paste your old FXML code, but make sure you replace the old fx:controller="..." with the newly created one. Commented Nov 11, 2024 at 16:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.