0

I am working on a JavaFX project, and I am having trouble displaying the user interface. I keep getting this error:

Error: Could not find or load main class Main.SongApp
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

I am confused because my directory has no files named 'application' or 'Application.'

I have these three files and I am not sure why this code does not run. This is the main file that I try to display the user interface from: SongApp.java

public class SongApp extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        
        // create FXML loader
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("/SongLibraryProject/ControllerTing/SongLib.fxml"));
        
        // load fxml, root layout manager in fxml file is GridPane
        AnchorPane root = (AnchorPane)loader.load();

        // set scene to root
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setResizable(false);
        primaryStage.show();

    }

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

This file has my front end code from Scene Builder and the anchor table I am trying to display: SongLib.fxml

<AnchorPane minHeight="400.0" minWidth="747.0" prefHeight="400.0" prefWidth="747.0" style="-fx-background-color: #263238;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="SongLibrary.View.Controller">
             //front end(scenebuilder code)
</AnchorPane>

This is the the controller file: SongLibController.java

public class SongLibController {
    @FXML ListView<Song> songList;
    @FXML Button add;
    @FXML Button edit;
    @FXML Button delete;
    @FXML Text name;
    @FXML Text artist;
    @FXML Text album;
    @FXML Text year;
    @FXML TextField nameField;
    @FXML TextField artistField;
    @FXML TextField albumField;
    @FXML TextField yearField;

    private ObservableList<String> obsList;

    public void add(ActionEvent e) {
        System.out.println("add");
  }

    public void edit(ActionEvent e) {
        System.out.println("edit");
    }

    public void delete(ActionEvent e) {
        System.out.println("delete");
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Harry
  • 1
  • 1
  • Add your project structure. – SedJ601 Oct 05 '22 at 03:47
  • 3
    The `javafx.application.Application` class is from JavaFX, not your own project. And what that error suggests is that JavaFX is not on the module-path/class-path when you execute your project. Assuming Java/JavaFX 11+, you need to add JavaFX to the `--module-path` and, if your own code is not modular, use `--add-modules` (see [Getting Started with JavaFX 11+](https://openjfx.io/openjfx-docs/)). Or you could use a JDK distribution that includes JavaFX (e.g., BellSoft Liberica, Azul Zulu). – Slaw Oct 05 '22 at 04:49
  • Slaw’s Comment is correct but brief. For more info, search Stack Overflow thoroughly as this topic has been addressed many times. And study the OpenJFX site. – Basil Bourque Oct 05 '22 at 06:16

0 Answers0