JavaFX Maven Exception in Application start method - java

So I've been stuck with this problem for a few days now. I found and read a lot of posts here on stackoverflow and other sites, but none of the solutions worked for me. I have a problem with my JavaFX in my maven project. I use java 15 and JavaFX 15.0.1.
Here are files that I have in my project:
The pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Maven_javaFx</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
</dependencies>
</project>
Here is my Main.java class:
package main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("src/main/java/resources/mainH/view.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Here is the view.fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.controller">
<children>
<Pane layoutX="200.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0">
<children>
<Button layoutX="74.0" layoutY="100.0" mnemonicParsing="false" text="Button" />
</children>
</Pane>
</children>
</AnchorPane>
Here is the message that pops out when I try to compile my code:
C:\Users\rafal\.jdks\openjdk-15\bin\java.exe --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\lib\idea_rt.jar=64406:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\rafal\Desktop\studia\Różne\Maven_javaFx\target\classes;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1-win.jar -p C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar main.Main
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:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x5d7c5b47) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x5d7c5b47
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
at main.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:174)
... 1 more
Exception running application main.Main
Most post that I saw with that issue were resolved by changing the directory in getResource() method.I tried that and many other solutions as you can probably see in pom file. I ask you for help in resolving this problem as I have no more ideas on what to do. Any help will be appreciated.
Thank you for helping in advance.

Thanks to a comment from #JoséPereda I found the solution to my problem. The issue was missing JavaFX Maven plugin and missing VM arguments.

Related

Problem with hibernate + maven + mysql server configuration

I have a problem with connecting to mysql database that I have created on google cloud. I easily connected mysql workbench to the database but I have a problem with configuring hibernate in my maven project. Here is the error log that shows when I want to run my application:
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:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:468)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2562)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:24)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.boot.internal.PersistenceXmlParser.<clinit>(PersistenceXmlParser.java:54)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:81)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at java.persistence#2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at java.persistence#2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at SlidingPuzzle/controllers.Main.start(Main.java:36)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:174)
... 1 more
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 23 more
Exception running application controllers.Main
Here is my pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>controllers</groupId>
<artifactId>SlidingPuzzle</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<javafx.version>13</javafx.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.5.7.Final</version>
</dependency>
</dependencies>
</project>
My module-info file:
module SlidingPuzzle {
requires javafx.controls;
requires javafx.fxml;
requires java.persistence;
opens controllers to javafx.fxml;
exports controllers;
}
and my main file where i try too initialize an EntityManger and EntityManagerFactory:
package controllers;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import models.database.User;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class Main extends Application {
private static Stage stage;
public static Stage getStage(){
return stage;
}
public static void setStage(Stage stage){
Main.stage = stage;
}
#Override
public void start(Stage primaryStage) throws Exception{
setStage(primaryStage);
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("/views/main.fxml"));
AnchorPane anchorPane = loader.load();
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("manager1");
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction entityTransaction=entityManager.getTransaction();
Scene scene = new Scene(anchorPane,1024,600);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
primaryStage.setTitle("Sliding Puzzle");
primaryStage.setMinHeight(600);
primaryStage.setMinWidth(1024);
primaryStage.setResizable(true);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I know that the error leads me to the moment where I try to create an EntityMAnagerFactroy but I don't know why does is show me that. Thanks for any help or a push in the right direction.
You need requires java.sql; in the module-info.java file in order to make use of the features of the java.sql module.
For more information, see a java 9 module tutorial.
There are likely other required modules that you will need to add to your module-info specification in order to get your application to work.

why FXMLLoader giving error when used to load a FXML file? [duplicate]

This question already has answers here:
Module error when running JavaFx media application
(2 answers)
Closed 2 years ago.
I was following a JavaFX tutorial and wrote the following code.
All the required header files are imported.
Main.java
public class Main extends Application {
#Override
public void start(Stage primaryStage){
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Random Number Generator");
primaryStage.show();
}catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Main.fxml (created using SceneBuilder)
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane minHeight="100.0" minWidth="100.0" prefHeight="300.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
<children>
<Button id="button_generateRandomNumber" layoutX="171.0" layoutY="212.0" mnemonicParsing="false" onAction="#generateRandom" text="Generate Random Number" textAlignment="CENTER" textFill="#1e4d0e" />
<Label fx:id="message" layoutX="112.0" layoutY="143.0" prefHeight="45.0" prefWidth="258.0" textAlignment="CENTER" />
</children>
</AnchorPane>
StackTrace
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x5d85fddd) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x5d85fddd
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at application.Main.start(Main.java:20)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:174)
... 1 more
Exception running application application.Main
I have tried every combination with getResource("Main.fxml") including relative and absolute path in every way possible still I am getting the error.
code is 100% same as of that tutorial.
In order to javafx work, you need to either download and import javafx sdk to your project or specify dependency, if you are using build tool like Maven or Gradle.
Moreover you need to add required modules (in this case javafx's .jars) either by using module-info.java and specifying required modules there, or adding modules to VM arguments - https://openjfx.io/openjfx-docs/#install-javafx.
Bonus:
Note that javafx was present in JDK up to version 10. Since version 11, they removed it. That is why you need to import javafx somehow to your project.

Failure # Application Start Method (JavaFX 11, JDK 14 & Intellij)

I'll try to keep this short but include as many details as I can, basically i'm trying to create a simple MPG calculator using Javafx but I've ran into a snag, whenever I attempt to run the main file some errors appear regarding the FXMLLoader but I cant for the life of me figure out why, I researched as many Q&A's as I could (and there is a lot of them) and I tried implementing the answers given but none of them worked.
Im pretty sure this is the cause of my pain.
Parent root = FXMLLoader.load(getClass().getResource("/sample/sample.fxml"));
I am pretty much a newbie when it comes to javafx so any assistance would be appreciated, if more information is required I will provide it.
File Structure
File Structure
Main
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/sample/sample.fxml"));
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
sample.FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<GridPane alignment="center" hgap="10" prefHeight="267.0" prefWidth="251.0" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<children>
<AnchorPane prefHeight="279.0" prefWidth="251.0">
<children>
<Label layoutX="12.0" layoutY="14.0" prefHeight="35.0" prefWidth="233.0" text="Miles Per Gallon Calculator" textAlignment="CENTER" underline="true">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="16.0" layoutY="69.0" prefHeight="27.0" prefWidth="50.0" text="Miles">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="16.0" layoutY="113.0" prefHeight="27.0" prefWidth="68.0" text="Gallons">
<font>
<Font size="18.0" />
</font>
</Label>
<Button layoutX="27.0" layoutY="151.0" mnemonicParsing="false" onAction="#calculateMPG" prefHeight="42.0" prefWidth="206.0" text="Calculate MPG" />
<TextField fx:id="milesField" layoutX="84.0" layoutY="70.0" />
<TextField fx:id="gallonsField" layoutX="84.0" layoutY="114.0" />
<Label layoutX="16.0" layoutY="204.0" prefHeight="27.0" prefWidth="68.0" text="MPG">
<font>
<Font size="18.0" />
</font>
</Label>
<TextField fx:id="mpgField" layoutX="84.0" layoutY="205.0" />
</children>
</AnchorPane>
</children>
</GridPane>
Controller
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import java.text.DecimalFormat;
public class Controller {
DecimalFormat df = new DecimalFormat("#.###"); double mpg;
#FXML
private TextField milesField;
#FXML
private TextField gallonsField;
#FXML
private TextField mpgField;
#FXML
void calculateMPG(ActionEvent event) {
try {
double miles = Double.parseDouble(milesField.getText());
double gallons = Double.parseDouble(gallonsField.getText());
if(gallons == 0){
mpgField.setText("Cannot Divide by zero");
}
else {
mpg = miles / gallons;
mpgField.setText(df.format(mpg));
}
} catch (NumberFormatException e){
mpgField.setText("Please enter real numbers.");
}
}
}
Error
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoSuchMethodError: 'java.lang.Object sun.reflect.misc.ReflectUtil.newInstance(java.lang.Class)'
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
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 sample.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:174)
... 1 more
Exception running application sample.Main
Process finished with exit code 1
As a quick side note, I was having issues setting up IntelliJ, for some reason when I imported JDK 14 for non-javafx programming it didnt import in any of the Jar files so I had to manually import those modules, same goes for JavaFX modules, here is the images of those as well, if something appears incorrect please let me know.
JDK1
JDK2
JDK3
Edit:
Just did a clean install of IntelliJ, JAvaFX,& JDK14, still got the same issue when I attempted to run the basic JavaFX "hello world" although the errors given are much more descriptive, Ill post the new errors here.
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x6af6aa0c) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x6af6aa0c
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at sample.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:174)
... 1 more
Exception running application sample.Main
Process finished with exit code 1
Edit 2:
Finally cleaned up the errors, after adding this line (see below) to VM options a single issue appeared. (Yes i put my path)
-p /%EnterPathToJavaFX%/lib --add-modules javafx.controls
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.base not found
Going to do some tinkering with the modules folder and see if i can fix this.
So after working on this for a couple of hours, i got a handle on the VM options (which was something I wasnt aware of when i first started) but i'm pretty sure the issue was caused by the use of forward and backward slashes, in a lot of the answers I read, they used forwards slashes instead of backwards slashes, I didnt realize this until about ten minutes ago, its a little embarrassing but, lesson learned.
Anyways, if youre still having this issue i'll give a basic rundown on what should be done (although there are a ton of good answers out there, just remember to use backslashes, dont be a dumb dumb like me).
Important Note: This implementation is for Windows Systems
1st:
Ensure that you have your JDK and JavaFX downloaded, try to keep the folder names simple (like JDK14 or JavaFX14).
2nd:
Open a new project and select your "Project SDK", in our case select the JDK you downloaded.
3rd:
After creating the project go to File -> Project Structure, then under 'Project Settings' select Libraries, then click the Plus icon to the right of project settings, select Java then navigate to your JavaFX folder and select 'lib'.
4th:
If you run the project now, you will get a runtime error, instead go to Run (at the top) then select 'Edit Configurations'. In the 'VM Options:' text field enter:
-p *Your_Drive_Partition*:\*path_to_JFX*\JavaFX\lib --add-modules=javafx.controls,javafx.fxml
And now you're done, welcome to JavaFX.
TL;DR: Forward slashes are for URI's and backslashes are for local (windows) files, do not forget this or end up in the same situation as me, going insane from doing the same thing over and over again expecting a different result.
Have a good day.

JavaFX Exception in Application start method when executed with Spring Boot

I have created a simple javaFX program and i added spring boot to javaFX by making the project a maven project. Before adding spring boot i got no error and the application worked fine.
I have provided the complete code below
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
</parent>
<groupId>groupId</groupId>
<artifactId>RMI-DesktopClient</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
AlarmsystemApplication.java
#Configuration
#SpringBootApplication
public class AlarmSystemApplication extends Application {
private ConfigurableApplicationContext applicationContext;
#Override
public void init() throws Exception {
this.applicationContext = SpringApplication.run(AlarmSystemApplication.class);
}
#Override
public void stop() throws Exception {
applicationContext.close();
}
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
Login.loadView(stage);
}
}
Login.java
public class Login {
public static void loadView(Stage stage) {
try {
Parent view = FXMLLoader.load(Login.class.getResource("../../../../../resources/com.ui.views/Login.fxml"));
stage.setScene(new Scene(view));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Login.fxml
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.alarmsystem.ui.views.Login">
<children>
<Label layoutX="137.0" layoutY="157.0" text="Hello JavaFX">
<font>
<Font size="59.0" />
</font>
</Label>
</children>
</AnchorPane>
The error that i get
Exception in Application start method
2020-04-23 22:33:12.134 INFO 7228 --- [lication Thread] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-04-23 22:33:12.136 INFO 7228 --- [lication Thread] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-04-23 22:33:12.139 INFO 7228 --- [lication Thread] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
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 com.alarmsystem.ui.views.Login.loadView(Login.java:16)
at com.alarmsystem.ui.AlarmSystemApplication.start(AlarmSystemApplication.java:34)
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
Exception running application com.alarmsystem.ui.AlarmSystemApplication
Process finished with exit code 1
The file structure
The resources path
I'm not sure this is Spring related; the resource name you use for your FXML is not a valid resource name (and the stack trace indicates that not being able to find the FXML file is the issue).
Specifically, resource names cannot have . in them, so .. and com.ui.views are both invalid.
So there are two problems here: one is that the resources name doesn't work with "parent directories" specified in it, and the other is that you have created a folder (not a package) under resources with illegal . characters in it. Also note that resources is a source folder, and is not available at runtime.
So, first, create a package under resources called com.ui.views and place the FMXL in there. I don't use IntelliJ, so I'm not sure if there is an option to do this, but if not you can create a folder com, a subfolder of it called ui, and a subfolder of that called views, and place the FXML file in views.
Then the correct resource name for the FXML, assuming you are using Maven defaults for your build, is
Parent view = FXMLLoader.load(Login.class.getResource("/com/ui/views/Login.fxml"));
If you restructure slightly so that the FXML file and Login class are in the same package (i.e. you make a com.alarmsystem.ui.views package under resources), then you can just do
Parent view = FXMLLoader.load(Login.class.getResource("Login.fxml"));
If you need to troubleshoot further, you can see where the resources were deployed (so where they are found at runtime), by looking in the target/classes folder.

JavaFX / Intellij errors

I'm trying to set up my programing environment in Java.
I Have Ubuntu 18.04LTS / Java SE Runtime Environment (build 13.0.1+9)/ Intellij/ JavaFX Scene Builder 11.0.0
I have followed this tutorial : https://www.youtube.com/watch?v=T3NlWMzPyXM
The following 3 files were created:
Main.java :
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller.java :
package sample;
import javafx.event.ActionEvent;
public class Controller {
// I start writing the code here:
public void pressButton(ActionEvent event) {
System.out.println("You have pressed the button");
}
}
sample.fxml :
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane alignment="center" hgap="10" prefHeight="300.0" prefWidth="300.0" vgap="10" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<children>
<Button fx:id="btn_msg" mnemonicParsing="false" onAction="#pressButton" prefHeight="109.0" prefWidth="121.0" text="Button" />
</children>
</GridPane>
When I run application I receive the following output errors:
/usr/lib/jvm/java-13-oracle/bin/java --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED -Djava.library.path=/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib -javaagent:/snap/intellij-idea-community/185/lib/idea_rt.jar=34245:/snap/intellij-idea-community/185/bin -Dfile.encoding=UTF-8 -classpath "/home/leo/IdeaProjects/Java kurs kenis/FX_trial2/out/production/FX_trial2:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/src.zip:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx-swt.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.web.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.media.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.swing.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.controls.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.graphics.jar" -p /home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/leo/IdeaProjects/javafx-sdk-11.0.2/lib/javafx.graphics.jar sample.Main
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0xc9d8652) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0xc9d8652
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at sample.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application sample.Main
Process finished with exit code 1
I can't find any solution for this. Can anybody help?
Finally I have worked the problem out.
I put the line:
--module-path /home/leo/MyApps/javafx-sdk-13.0.1/lib --add-modules=javafx.controls,javafx.fxml
here:
Run > Edit Configuration > VM options
and:
File > Project structure > Libraries > + choose the directory:
/home/leo/MyApps/javafx-sdk-13.0.1/lib
You used
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
Try:
Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));

Categories

Resources