5

I must say that I am not much familiar with Java, I am working on assignment for my university classes.

I want to make a Desktop Application with JavaFX and SceneBuilder, I'm using this tutorial on YouTube: https://www.youtube.com/watch?v=DH3dWzmkT5Y

Everything is working fine until in 17:25 he created module-info.java file

module HotelBookingSystemTest1 {
    requires javafx.graphics;
    requires javafx.fxml;
    requires javafx.controls;
    requires java.sql;
    requires mysql.connector.java;

    opens sample;
}

I do the same in my project, but after running I am getting this error:

/home/prem/.jdks/openjdk-15.0.2/bin/java --module-path /home/prem/Downloads/javafx-sdk-16/lib --add-modules javafx.controls,javafx.fxml -Djava.library.path=/home/prem/Downloads/javafx-sdk-16/lib -javaagent:/snap/intellij-idea-community/289/lib/idea_rt.jar=44433:/snap/intellij-idea-community/289/bin -Dfile.encoding=UTF-8 -m HotelBookingSystemTest1/sample.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module HotelBookingSystemTest1 not found

Process finished with exit code 1

I'm pretty sure that I put the file in the right place, here is my project directories tree:

enter image description here

Could someone help me with fixing that error and explain why this is happening? Thank you!

Przemek Baj
  • 426
  • 2
  • 5
  • 18
  • What directory is your built module put into? Is it `out`? And what directory are you calling `java` from? – Thomas Mar 29 '21 at 13:56
  • clean/rebuild your project - if your own module is not found there is something weird in your setup, most probably some stale state in the build output – kleopatra Mar 29 '21 at 14:03
  • @Thomas Yes, I think that's an "out" directory. I guess Java is run from here "/home/prem/.jdks/openjdk-15.0.2/bin/java" as it's written in error. Anyway, I think that's not the case - when I'm removing the "module-info.java" file, everything is working properly! – Przemek Baj Mar 29 '21 at 14:03
  • @kleopatra I have the same error after removing 'out' folder and building/running again. The guy on the tutorial didn't change anything in the running configuration. Also, two of my friends are trying to run it and they have the same error. – Przemek Baj Mar 29 '21 at 14:08

3 Answers3

4

You're getting that error because you didn't include its path in your VM options. All you have to do is find out where your code is outputting to and add that path to any existing ones such as this one:

--module-path "<your-path>" --add-modules javafx.controls,javafx.fxml

It looks like your project's output directory is "out" (more than likely under productions) but you can always double check this by going to File -> Project Structure -> Project -> Project compiler output and then figure out where your module is located from there (in your case you'd be looking for HotelBookingSystemTest1). After copying its address and adding it to the code above it should look something like this:

--module-path "<your-path>;<copied-address>" --add-modules javafx.controls,javafx.fxml

Here is one of my paths for reference, although in this case my output directory was "classes":

--module-path "C:\Program Files (x86)\JavaFX\javafx-sdk-16\lib;C:\Users\ethan\Documents\Code\GeneralPlanner\classes\production" --add-modules javafx.controls,javafx.fxml

Also make sure the SDKs in your run configuration and module settings are the same. If it gives you an error about the sql connector or any other module not found, be sure to add their paths to the existing ones as well (same way with the semicolon).

Dharman
  • 30,962
  • 25
  • 85
  • 135
ETHN
  • 74
  • 6
1

To complement the previous answer, you can follow the path you found on "File -> Project Structure -> Project -> Project compiler output" in the project structure frame and there you can copy the module path with Right Click on the module name -> Copy Path.

Then you can find the VM Options clicking on Run -> Edit Configurations.

0

For anyone getting this error using maven just move the module-info file into your source directory which normally for maven projects is "src/main/java" or if its different move youre module-info file from project directory to the new source directory it should work

Ted N
  • 1