1

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

This is my project structure

  • This error also occur when i am working in webView. – Suman Kumar Apr 11 '22 at 07:25
  • 1
    Does this answer your question? [Java FX Modular Application, Module not found (Java 11, Intellij)](https://stackoverflow.com/questions/53447738/java-fx-modular-application-module-not-found-java-11-intellij) – Islam Assem Apr 11 '22 at 08:33
  • You don’t need to `--add-modules` when you have a module info, you still need a module path for your code and required modules. Easiest fix is [idea new JavaFX project](https://www.jetbrains.com/help/idea/javafx.html#check-plugin), this will create a maven project and idea and maven will understand the modularity and put all the required modules (including your code and the dependent JavaFX modules) on your build and run path automatically. – jewelsea Apr 12 '22 at 05:23
  • If you also want webview to work, [follow the instructions here](https://stackoverflow.com/questions/70942561/can-not-resolve-symbol-javafx-scene-web/70946444#70946444). – jewelsea Apr 12 '22 at 05:27

0 Answers0