I am trying to run a simple JavaFX file. See my code below.
package com.example.multiplayer_snake;
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 {
@SuppressWarnings("exports")
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("/Multiplayer_Snake/src/main/resources/com/example/multiplayer_snake/hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
stage.setTitle("Snake");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
And my folder structure is looking like in this picture
What I've figured out so far is it has something to do with my absolute path to the .fxml file. If I manually copy the .fxml file into my package and change the path to "hello-view.fxml" I am able to run it. But I don't always want to move/copy the file manually whenever the .fxml file is changed.
"/Multiplayer_Snake/src/main/resources/com/example/multiplayer_snake/hello-view.fxml"
But I don't really get why I am still running into errors. Any solutions how to determine the correct path?