3

A java newbie here. I wanted to learn about JavaFX on VSCode but when I launch my JavaFX it gave me this error. I tried to add referenced Library and the configurations vmArgs on launch.json on the project, but it giving me the same thing.

Here is my config.

"vmArgs": "--module-path C:/Users/vince/Downloads/javafx-sdk-17.0.1/lib --add-modules javafx.controls,javafx.fxml"

Can anyone help me please ?

Abra
  • 19,142
  • 7
  • 29
  • 41
mc ser
  • 43
  • 1
  • 7
  • Not related to your question but. I advise moving the sdk out of the download directory to sonewhete more permanent. – jewelsea Jan 10 '22 at 06:37
  • I don’t know vscode, but comparing your arguments to a [similar question](https://stackoverflow.com/questions/54349894/javafx-11-with-vscode), the arguments look ok, so I don’t know how to fix that. – jewelsea Jan 10 '22 at 06:53
  • @jewelsea i did try to move my javaFX jdk to another place and updated it to VMargs but still same – mc ser Jan 10 '22 at 06:54
  • You could switch to a jdk that includes JavaFX, e.g. an appropriate version of [liberica](https://bell-sw.com/pages/downloads/#mn) or corretto, then you don’t need any arguments, or try idea with the [new project wizard](https://www.jetbrains.com/help/idea/javafx.html) which is an easy way to get started. – jewelsea Jan 10 '22 at 06:57
  • A past question like this was solved by [escape quoting the path](https://stackoverflow.com/questions/15637429/how-to-escape-double-quotes-in-json), but I don’t think that is your issue here. – jewelsea Jan 10 '22 at 06:59
  • @jewelsea just tried to escape quoting path still same tho – mc ser Jan 10 '22 at 07:11
  • Set `args` in launch.json, does it help? – Molly Wang-MSFT Jan 10 '22 at 09:26
  • @MollyWang-MSFT nope, i tried to add vmArgs and im sure the path is correct – mc ser Jan 10 '22 at 10:28
  • 1
    @mcser. After adding vmArgs, please restart VS Code to make the change effective. – Molly Wang-MSFT Jan 11 '22 at 02:16

5 Answers5

3

Solution: You simply need some edits in your "vmAgrs" in the "launch.json" file

"vmArgs": "--module-path \"C:/Users/vince/Downloads/javafx-sdk-17.0.1/lib\" --add-modules javafx.controls,javafx.fxml"

General form of the solution:

"vmArgs": "--module-path \"enter_the_path_here\" --add-modules javafx.controls,javafx.fxml"

Use this and your code should work perfectly.

I was having the same problem and wasted almost 4 hours solving this. I used this video here: link! as reference. (Caution: the video is in Portuguese)

1

Check out the samples here: https://github.com/openjfx/samples/tree/master/IDE/VSCode

You can probably use this one, which I guess is the one you are looking for.

Sheng Chen
  • 1,012
  • 4
  • 18
  • very useful, thanks – littlejedi Jan 11 '22 at 02:33
  • It would be good if this answer included a code snippet or something in the answer for the bit which makes “ (probably this one) which is suitable for you. ” Pull requests and forks can get deleted which would render this largely link only answer useless. – jewelsea Jan 11 '22 at 04:31
  • I'll update the answer once the PR is merged. – Sheng Chen Jan 20 '22 at 00:40
0

I didn't fix the javafx in my vs code, but i switched IDE to Eclipse and JavaFX run smoothly after adding VMargs to the run configuration on Eclipse

mc ser
  • 43
  • 1
  • 7
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 14 '22 at 11:49
0

If you still get this error after setup "vmAgrs", and your using debug/launch-(F5)-to start your App, its possible that VSCode wouldn't launch your "App.java" file, instead will try to launch "Current file" which is something else..

To fix it just change "Launch Current file" to "Launch App" from "Start debugging" in "Run and Debug" icon.


Anyway if any of this didn't work, you could Run it manually by:

1st compile using javac

javac --module-path "PATH\javafx-sdk-19.0.2.1\lib"  --add-modules javafx.controls App.java

2nd Run it..

java --module-path "PATH\javafx-sdk-19.0.2.1\lib"  --add-modules javafx.controls App

thanks to Casey LINK

Taq
  • 1
-1

Try putting everything on one drive other than C. I had my codes in D drive and JavaFX in C, the codes never launched successfully. It didn't work even when I put the codes in the JavaFX folder. However, once I transferred JavaFX files to D drive, it worked.

KJI245
  • 1