0

So I have downloaded JavaFX SDK, I'm working with IntelliJ Idea editor. I set it in the system and user environment variables path: C:\Program Files\Java\javafx-sdk-17.0.2\lib

This is the code I am trying to work with:

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(" ");
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

I put this into Virtual Machine options which are located Run -> Edit Configurations: --module-path %PATH_TO_FX% --add-modules=javafx.controls. But I'm still getting the following error: java.lang.module.FindException: Module javafx.controls not found.

This is a Project Structure:

enter image description here

This is using a path of a library:

enter image description here

Jan Tuđan
  • 233
  • 3
  • 17
  • Open File -> Project Structure and check your Project SDK setting there. Is it pointing to the same JDK? – Thomas Timbul Jan 23 '22 at 16:31
  • @ThomasTimbul I'm not sure, SDK version is 17, and java-fx SDK (which is in global library) is 17.0.2, does this matter? I uploaded a screenshot – Jan Tuđan Jan 23 '22 at 16:43
  • Looks correct (full path shown right hand side). Is it a modular project? If you have module-info.java in your project, you may need to add JavaFX as a dependency there, or delete the file (making your own project non-modular). Also check that the JavaFX plugin has been enabled as per https://www.jetbrains.com/help/idea/javafx.html#check-plugin – Thomas Timbul Jan 23 '22 at 16:57
  • @ThomasTimbul my project is non-modular, so I don't understand where is the problem – Jan Tuđan Jan 23 '22 at 17:20
  • @jewelsea I was trying to use quotes on the path and also on the environment variables but it still did not affect any changes, I also tried adding it on a location without spaces and the same error occurs. – Jan Tuđan Jan 23 '22 at 17:23
  • Can you exactly write detailed answer how to use wizard with a build tool so I can follow the steps? – Jan Tuđan Jan 23 '22 at 17:30
  • "Can you exactly write detailed answer how to use wizard with a build tool so I can follow the steps?" -> No, follow the new project link I supplied, it provides all of the steps you need and documents them in a much better way than I could writeup in an answer. – jewelsea Jan 23 '22 at 17:33
  • @jewelsea okay, I followed the documents in the answer which you sent to me, I added quotes on the actual path because of spaces on keywords of the paths. But I got the same problem again. I uploaded a 2nd screenshot. – Jan Tuđan Jan 23 '22 at 17:46
  • Thanks for the 2nd screenshot, it is helpful. You did not: "Expand the Java execution command which idea puts in the console pane on execution and copy it as text to add to your question formatted as code." – jewelsea Jan 23 '22 at 18:20
  • Possible duplicate: [JavaFX Modular Application, java.lang.module.FindException: Module javafx.controls not found (Java 11, Intellij)](https://stackoverflow.com/questions/53795661/javafx-modular-application-java-lang-module-findexception-module-javafx-contro) – jewelsea Jan 23 '22 at 20:42
  • We all trusted, but have you verified that your JDK actually includes these modules? You can do so by selecting "17 (Version 17)", i.e. the top entry, in your first screenshot (project structure) and pressing F4. This will navigate to the selcted JDK within the Platform Settings -> SDKs panel. Double check that there are entries for the javafx modules. If not, I personally use liberica - https://bell-sw.com/pages/downloads/#/java-17-lts%20/%20current. If downloading you need to select the FULL JDK. Standard does not include JavaFX. – Thomas Timbul Jan 26 '22 at 13:40

1 Answers1

0

Your second screenshot shows a relative directory for the module path rather than an absolute directory.

Your module path needs to include C:\ because that is where you have the SDK, otherwise it won't be found.

You are running windows so your separator used in the --module-path should be \ not /. The java command may be smart enough to work out the correct path regardless of the separator used, but I wouldn't rely on that.

For further troubleshooting information and advice, see the answers to:

jewelsea
  • 150,031
  • 14
  • 366
  • 406