IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaFX Discussion :

Problème:Exception in Application start method


Sujet :

JavaFX

  1. #1
    Futur Membre du Club
    Homme Profil pro
    M1 Informatique
    Inscrit en
    Décembre 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Hautes Pyrénées (Midi Pyrénées)

    Informations professionnelles :
    Activité : M1 Informatique

    Informations forums :
    Inscription : Décembre 2016
    Messages : 5
    Points : 7
    Points
    7
    Par défaut Problème:Exception in Application start method
    Bonjour a tout le monde, j'ai un problème a l'utilisation de JavaFX que je n'arrive pas a résoudre ... (je travaille sous netbeans 8.2)
    J'ai créer un projet JavaFX avec plusieurs package :
    "ch.makery.GPAO"
    composé de " view" et de "model"
    Dans ch.makery.GPAO.view j'ai deux fichier "ArticleOverview.fxml" et "RootLayout.fxml"
    Dans ch.makery.GPAO j'ai ma classe principale "MainApp.java" dont voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    package ch.makery.GPAO;
     
    import java.io.IOException;
     
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Scene;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
     
    public class MainApp extends Application {
     
        private Stage primaryStage;
        private BorderPane rootLayout;
     
        @Override
        public void start(Stage primaryStage) {
            this.primaryStage = primaryStage;
            this.primaryStage.setTitle("GPAO_App");
     
            initRootLayout();
     
            showArticleOverview();
        }
     
        /**
         * Initializes the root layout.
         */
        public void initRootLayout() {
            try {
                // Load root layout from fxml file.
                FXMLLoader loader = new FXMLLoader();
                loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
                rootLayout = (BorderPane) loader.load();
     
                // Show the scene containing the root layout.
                Scene scene = new Scene(rootLayout);
                primaryStage.setScene(scene);
                primaryStage.show();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
        /**
         * Shows the person overview inside the root layout.
         */
        public void showArticleOverview() {
            try {
                // Load person overview.
                FXMLLoader loader = new FXMLLoader();
                loader.setLocation(MainApp.class.getResource("view/ArticleOverview.fxml"));
                AnchorPane ArticleOverview = (AnchorPane) loader.load();
     
                // Set article overview into the center of root layout.
                rootLayout.setCenter(ArticleOverview);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
        /**
         * Returns the main stage.
         * @return
         */
        public Stage getPrimaryStage() {
            return primaryStage;
        }
     
        public static void main(String[] args) {
            launch(args);
        }
    }
    A la compilation, j'obtient l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    	at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ClassCastException: javafx.scene.layout.AnchorPane cannot be cast to javafx.scene.layout.BorderPane
    	at ch.makery.GPAO.MainApp.initRootLayout(MainApp.java:36)
    	at ch.makery.GPAO.MainApp.start(MainApp.java:23)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    	... 1 more
    Exception running application ch.makery.GPAO.MainApp
    Java Result: 1
    Deleting directory D:\Zeus\WinZeus\Documents\NetBeansProjects\JavaFX_GPAO\dist\run1056974998
    jfxsa-run:
    BUILD SUCCESSFUL (total time: 1 second)
    Si vous pouviez m'aidez, je serais sauvé ...

    Edit : C'est bon j'ai réussi ^^

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    L'erreur est plutôt clairement décrite : Caused by: java.lang.ClassCastException: javafx.scene.layout.AnchorPane cannot be cast to javafx.scene.layout.BorderPane.

    La racine de ton FXML est un AnchorPane mais tu le cast en BorderPane dans ton code juste après l'avoir chargé -> ClassCastException
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème Exception EOFException
    Par jason69 dans le forum Entrée/Sortie
    Réponses: 1
    Dernier message: 04/09/2006, 14h47
  2. [Dates] Problème avec mon application
    Par gtraxx dans le forum Langage
    Réponses: 16
    Dernier message: 21/08/2006, 20h59
  3. Réponses: 1
    Dernier message: 17/05/2006, 20h00
  4. [JBOSS] [Struts] Problème avec une application
    Par Tiercel dans le forum Wildfly/JBoss
    Réponses: 5
    Dernier message: 13/07/2004, 13h50
  5. problème connexion à certaines applications ?
    Par Cornell dans le forum MS SQL Server
    Réponses: 12
    Dernier message: 27/02/2004, 17h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo