JavaFX export du java

Résolu/Fermé
PlagLeFleau Messages postés 8 Date d'inscription samedi 5 mars 2022 Statut Membre Dernière intervention 21 septembre 2022 - 21 sept. 2022 à 16:21
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 21 sept. 2022 à 18:35

Bonjour,

J'ai un message d'erreur lorsque j'execute mon jar il me dis ceci

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: Location is not set.
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2541)
	at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
	at fr.plaglefleau.shutdown.HelloApplication.start(HelloApplication.java:14)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
	... 1 more

j'ai donc regarder dans le HelloApplication.java
et j'ai ceci

package fr.plaglefleau.shutdown;

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("hello-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load());
        stage.setTitle("Shutdown à Distance");
        stage.setScene(scene);
        stage.setResizable(false);
        stage.show();
    }

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

Si quelqu'un peut m'aider
Windows / Firefox 104.0

A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
21 sept. 2022 à 18:35

Bonjour,

Dans cette ligne de code, le programme n'a pas trouvé le fichier hello-view.fxml :

new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"))

En général c'est parce que le dossier dans lequel se trouve le fichier n'est pas celui qui est utilisé à l'exécution.

Par exemple, si le fichier est à la racine, il faudrait plutôt écrire "/hello-view.fxml" avec le / qui indique que c'est la racine. Sans cela il va chercher le fichier en relatif au dossier courant et vu que tu y accèdes via la classe HelloApplication il doit le chercher dans le même dossier que le package fr/plaglefleau/shutdown


1