-1

Beginner here with JavaFX. I'm working on a Java project with JavaFX and it works completely fine on Eclipse. When I use Visual Studio Code on the other hand, I get errors that look like this:

FridgeGUI.java:1: error: package javafx.application does not exist
import javafx.application.Application;

For me, I prefer Visual Studio Code for the ease of use, but I cannot find what is wrong with it. I believe I added JavaFX correctly using Referenced Libraries. Does anyone know why?

Code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FridgeGUI extends Application {
    Button button;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Fill Up the Fridge!");
         
          button = new Button("Enter");
         
          StackPane layout = new StackPane();
          layout.getChildren().add(button);
         
          Scene scene = new Scene(layout, 700, 700);
          primaryStage.setScene(scene);
          primaryStage.show();
        
    }

}

  • Most likely you've got your source folder set wrong. – Dawood ibn Kareem Jun 01 '22 at 04:01
  • Your source file isn’t wrong or you wouldn’t be able to attempt to compile your own code, which you can clearly attempt to do, because your code is throwing compile errors. – jewelsea Jun 01 '22 at 04:15
  • 4
    Go to openjfx.io. Read the getting started guide for vscode. Follow it. Your library of module setup is wrong. Alternately download Bellsoft liberica “full jdk” and use that (it includes JavaFX so you don’t need additional setup or vm arguments or maven modules or the JavaFX sdk). – jewelsea Jun 01 '22 at 04:16
  • 4
    [Working with GUI applications in VS Code](https://code.visualstudio.com/docs/java/java-gui#:~:text=Step%201%3A%20Install%20the%20Extension,JavaFX%20project%20via%20Maven%20Archetype.) – MadProgrammer Jun 01 '22 at 04:31
  • 4
    [JavaFX-11 with VSCode](https://stackoverflow.com/questions/54349894/javafx-11-with-vscode) – MadProgrammer Jun 01 '22 at 04:32
  • 4
    [Java on Visual Studio Code Update – February 2022](https://devblogs.microsoft.com/java/java-on-visual-studio-code-update-february-2022/) – MadProgrammer Jun 01 '22 at 04:32

0 Answers0