JavaFX application unable to launch after I've modelled the FXML with SceneBuilder

32 Views Asked by At

Just finished creating a basic UI on SceneBuilder and saved the FXML onto Java, but now whenever I launch the application [HelloApplication] it gives an error about fxml location not being set

Is this due to an incorrect resource directory or name?

HelloApplication code:

package com.example.oneschoolmanager_tst.Testers;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("main-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load());
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();
    }

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

the project folder, main-view.fxml is what i'm trying to access

When run it gives an IllegalStateException with message Location is not set at line 14.

1

There are 1 best solutions below

0
Thomas Behr On

Is this due to an incorrect resource directory or name?

Yes.

If you load your FXML file with HelloApplication.class.getResource("main-view.fxml"), your FXML file needs to be in the same (relative) path as class HelloApplication.

I.e. your FXML file needs to be in directory com/example/oneschoolmanager_tst/Testers.