Reputation: 93
I'm using visual studio code for my IDE. I was having trouble setting up JavaFX 15.0.1; I have java 14.0.2. I'm using the latest version of VSC.
When trying to run the code I was getting the run-time error, "components missing..." but now getting I am getting the error
Error: Could not find or load main class Lib.javafx-sdk-15.0.1.lib Caused by: java.lang.ClassNotFoundException: Lib.javafx-sdk-15.0.1.lib.
File location of the project: D:\ServerAPI\helloWorld
File location for the JavaFX jar files: E:\Java Lib\javafx-sdk-15.0.1\lib
I'm fairly new to programming so any explanation would be deeply appreciated.
This is the code I used from github to test it.
package serverAPI;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
This is the launch.Json configuration I edited in VSC:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - App",
"request": "launch",
"vmArgs": "--module-path E:/Java Lib/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml",
"mainClass": "serverAPI.App",
"projectName": "helloWorld_8408fb31"
},
]
}
I don't know any other details that I should put in here.
Upvotes: 0
Views: 849
Reputation: 33
This issue is in your json file. on the vmArgs line:
"vmArgs": "--module-path E:/Java Lib/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml",
You can't have a space in the path. So you need to move this library to a location that doesn't include a space in the path.
Upvotes: 3