When using idea based on maven to write JavaFX demo, the fxml path is correct, but it keeps reporting error when running that the fxml file does not exist, tried multiple paths, still not working, then found that the files in the src directory, except the .java ones, will not compile.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at org.gmk.App.start(App.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
… 1 more
The written code and file directories are shown below.
public class App extends Application {
public static void main( String[] args )
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Code Generator");
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene=new Scene(root,818.4,399);
primaryStage.setScene(scene);
primaryStage.show();
}
}
In this case, you need to configure in Maven and declare the files to be compiled during compilation:
<build>
<resources>
<!--Add both resource nodes, if you have configuration files in both directories. If you add only one resource node, it will only compile the xml and properties files in the directory configured by this node-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
Then refresh Maven and compile fxml when recompiling.
Read More:
- JavaFX 11: “missing JavaFX runtime component”
- How to Fix The error may exist in com/kuang/dao/UserMapper.xml
- Jdk11, using JavaFX in eclipse
- How to Fix Invalid bound statement (not found) Error
- How to Fix Spring Boot OTS parsing error: Failed to convert WOFF 2.0
- How to Fix error performing isolated work; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarE
- How to Fix Session is not Connecting (How to Diagnose it)
- Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure (How to Fix)
- How To Fix Windows Java Error 1723
- ERROR: Failed to parse POMs (How to Fix)
- How to Fix stack overflow error
- How to Fix Tomcat Error: Failed to destroy end point associated with ProtocolHandler[ajp-nio-8009]
- How to Fix Error sal.h(2367)
- failed: Too many links (How to Fix)
- Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded (How to Fix)
- HTTP Error 502.5 – Process Failure (How to Fix)
- How to Fix IWAB0489E Error when deploying Web service to Axis runtime
- How to Fix “Slow Access of Stackoverflow” Issue
- Android resource compilation failed (How to Fix)
- How to Fix “junit.framework.Comparison Failure Expected: but was”