Creating simple javafx 17.0.2 application. Getting error.
- OS: Windows 11
- Java SE Development Kit: 17.0.2
- javafx: 17.0.2
Error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module aparajita.suman.demo not found
hello-view.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.media.MediaView?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="aparajita.suman.demo.HelloController">
<children>
<MediaView fitHeight="360.0" fitWidth="600.0" layoutY="7.0" />
<Button fx:id="playButton" layoutX="72.0" layoutY="367.0" mnemonicParsing="false" text="Play" />
<Button fx:id="pauseButton" layoutX="236.0" layoutY="367.0" mnemonicParsing="false" text="Pause" />
</children>
</fx:root>
HelloApplication.java
package aparajita.suman.demo;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
In pom.xml
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17.0.2</version>
</dependency>
module-info.java
module aparajita.suman.demo {
requires javafx.controls;
requires javafx.fxml;
requires javafx.media;
opens aparajita.suman.demo to javafx.fxml;
exports aparajita.suman.demo;
}
In VM option
--module-path "C:\Users\HP\Downloads\javafx-sdk-17.0.2\lib" --add-modules javafx.media,javafx.controls