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 :

null pointer sur un @FXML


Sujet :

JavaFX

  1. #1
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut null pointer sur un @FXML
    Bonjour, Bonsoir
    j'aurai besoin d'aide sur un truc que je trouve un peu bizarre. J'ai une ListView dans une fenêtre fait avec SceneBuilder, je lui est mis l'id "listView" et quand je veux l'utiliser comme dans le code suivant j'ai un NullPointerException et je ne comprends pas pourquoi car quand je veux faire quelque chose avec le canvas juste au dessus j'ai pas de problème et à ma connaissance normalement je n'ai pas besoin de faire un new dessus. Si quelqu'un sait quelque chose qu'il m'aide svp.

    Dans cette listView je voudrai mettre les noms des fichiers qui sont dans un répertoire nommé "exemples". L'action est lancé grace à un bouton dans une première fenêtre ensuite je charge la deuxième fenêtre simple avec une ListView et un Label qui doit afficher les noms des fichiers.

    Code controleur:
    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
     
    @FXML public Canvas canvas;
    @FXML public ListView<String> listView;
     
    @FXML
    public void rechercheFichier() throws IOException {
    	Stage stage=new Stage();
    	FXMLLoader loader=new FXMLLoader(Main.class.getResource("ChargeFichier.fxml"));
    	Parent root=loader.load();
     
    	ObservableList<String> filesName=FXCollections.observableArrayList();
    	listView.setItems(filesName);
    	File path=new File("exemples");
    	for(File f : path.listFiles()) {
    		filesName.add(f.getName());
    	}
     
    	stage.setTitle("Recherche Fichier");
    	stage.setScene(new Scene(root));
    	stage.show();
    }
    et l'erreur (le null pointer est sur la ligne "listView.setItems(filesName);" ligne 12):
    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
    Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    	at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
    	at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    	at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    	at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    	at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8890)
    	at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
    	at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
    	at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    	at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    	at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    	at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3862)
    	at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
    	at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2590)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
    	at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
    	at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    	at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    	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:174)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.reflect.InvocationTargetException
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
    	at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
    	at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
    	at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1784)
    	... 46 more
    Caused by: java.lang.NullPointerException
    	at projetmode_g6.projetmode_g6/control.ControlBoutons.rechercheFichier(ControlBoutons.java:48)

  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
    Citation Envoyé par kenyuki Voir le message
    je lui est mis l'id "listView" et quand je veux l'utiliser comme dans le code suivant j'ai un NullPointerException
    • fx:id - le nom du champ annoté @FXML à injecter dans le contrôleur.
    • id - la valeur de la propriété id du contrôle.
    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

  3. #3
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    Oui pardon c'est son fx:id
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
     <ListView fx:id="list" layoutY="63.0" onMouseClicked="#charge" prefHeight="337.0" prefWidth="292.0" />

  4. #4
    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
    Dans ce cas est-ce que tu pourrais me montrer comment tu charges ton FXML et son contrôleur, et aussi la ligne 48 de la classe ControlBoutons STP ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Caused by: java.lang.NullPointerException
    	at projetmode_g6.projetmode_g6/control.ControlBoutons.rechercheFichier(ControlBoutons.java:48)
    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

  5. #5
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    Voici:
    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
    @FXML
    public void rechercheFichier() throws IOException {
    	Stage stage=new Stage();
    	FXMLLoader loader=new FXMLLoader(Main.class.getResource("ChargeFichier.fxml"));
    	Parent root=loader.load();
     
    	ObservableList<String> filesName=FXCollections.observableArrayList();
    	list.setItems(filesName);                                            // <- Ligne de l'erreur (ligne 48)
    	File path=new File("exemples");
    	for(File f : path.listFiles()) {
    		filesName.add(f.getName());
    	}
     
    	stage.setTitle("Recherche Fichier");
    	stage.setScene(new Scene(root));
    	stage.show();
    }
    J'ai une première fenêtre dans laquelle je clique sur un bouton et ça me créé une nouvelle fenêtre (celle avec la ListView) les fichiers que je veux mettre dans la ListView sont dans exemples. Je sens que c'est quelque chose de très bête, que j'ai juste oublié quelque chose mais faut pas me taper dessus svp j'apprends x)

    Edit: j'ai changé listView par list pour pas faire de confusion j'avais oublié de préciser

  6. #6
    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
    1 seconde, qui est le contrôler de ChargeFichier.fxml ?
    Comment as-tu charge l'instance de la classe (qui semble être elle-même un contrôleur puisqu'il y a une annotation @FXML) dans laquelle tu te trouves au moment ou cette exception est levée ?
    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

  7. #7
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    j'ai une première fenêtre que je charge comme ci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    public void static main(String[] args){
      Stage stage=new Stage();
      FXMLLoader loader=new FXMLLoader(Main.class.getResource("PremiereFenetre.fxml"));
      Parent root=loader.load();
      stage.setTitle("Page d'acceuil");
      stage.setScene(new Scene(root));
      stage.show();
    }
    et dedans j'ai un bouton que j'ai link sur recherche fichier qui est sensé ouvrir une nouvelle fenêtre et afficher les fichiers dans un dossier exemples. J'arrive à afficher la fenêtre si je n'essaie pas de remplir la ListView mais en la remplissant j'ai une erreur. Et je trouvais ça très bizarre donc après des recherches infructueuses je me suis encore tourné vers ce forum qui m'avait déjà aidé.

  8. #8
    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
    Donc projetmode_g6.projetmode_g6/control.ControlBoutons (quel nom étrange) est bien le contrôleur de PremiereFenetre.fxml ? Je rappelle que comme tu postes que des petits bouts de code complètements sortis de leur contexte, sans nom de classe ou même le code complet du FXML, c'est pas forcément super facile à saisir.

    Est-ce que tu peux lui rajouter une méthode public void initialize() dans ce contrôleur et y mettre un assert pour tester que list soit pas null ?
    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

  9. #9
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    oui désolé, j'ai fait plusieurs classes pour décomposer le code et que ce soit plus facile à comprendre.
    Déjà j'ai une première fenêtre dans laquelle j'ai un bouton qui lorsqu'on clique dessus appelle cette fonction qui fait une nouvelle fenetre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    @FXML
    	public void rechercheFichier() throws IOException {
    		FenetreRechercheFichier f=new FenetreRechercheFichier();
    	}
    Là la classe FenetreRechercheFichier
    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
    public class FenetreRechercheFichier {
     
     
    	public FenetreRechercheFichier() {
    		Stage stage=new Stage();
    		FXMLLoader loader=new FXMLLoader(Main.class.getResource("ChargeFichier.fxml"));
    		Parent root = null;
    		try {
    			root = loader.load();
    		} catch (IOException e) {e.printStackTrace();}
     
    		ControlRechercheFichier r=new ControlRechercheFichier();
    		r.remplirList();
     
    		stage.setTitle("Recherche Fichier");
    		stage.setScene(new Scene(root));
    		stage.show();
    	}
    }

    Et là le controleur de cette nouvelle fenêtre ControlRechercheFichier:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    public class ControlRechercheFichier {
     
    	@FXML public ListView<String> list;
     
    	public void remplirList() {
    		ObservableList<String> filesName=FXCollections.observableArrayList();
    		list.setItems(filesName);
    		File path=new File("exemples");
    		for(File f : path.listFiles()) {
    			filesName.add(f.getName());
    		}
    	}
    }

    Et la je remes les erreurs (même si je pense que le plus interressant est à la fin je mes tous):
    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
    Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    	at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
    	at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    	at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    	at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    	at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8890)
    	at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
    	at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
    	at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    	at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    	at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    	at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    	at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    	at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3862)
    	at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
    	at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2590)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
    	at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
    	at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
    	at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    	at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    	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:174)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.reflect.InvocationTargetException
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
    	at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
    	at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
    	at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1784)
    	... 46 more
    Caused by: java.lang.NullPointerException
    	at projetmode_g6.projetmode_g6/control.ControlRechercheFichier.remplirList(ControlRechercheFichier.java:16)
    	at projetmode_g6.projetmode_g6/view.FenetreRechercheFichier.<init>(FenetreRechercheFichier.java:23)
    	at projetmode_g6.projetmode_g6/control.ControlBoutons.rechercheFichier(ControlBoutons.java:32)
    	... 57 more

    Et on ne critique pas mes choix de nom de classe x)

  10. #10
    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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    root = loader.load();
     
    [...]
     
    ControlRechercheFichier r=new ControlRechercheFichier();
    r.remplirList();
    Donc tu initialises bien une seconde instance du contrôleur à mano qui n'a absolument aucun lien avec le FXML que tu viens de charger ! Et donc forcément list est vide.

    • Soit ton contrôleur est décrit dans ton FXML et il est automatiquement chargé par le FXMLLoader et donc tu le récupères en faisant loader.getController() APRES avoir chargé le FXML.
    • Soit tu crées ton contrôleur à mano et tu l'injectes dans le loader AVANT de charger le FXML en faisant loader.setController().
    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

  11. #11
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    Hmm ok j'ai pas l'impression d'avoir tous bien compris je dois envoyer load dans remplirList en parametre et dans remplirList je fais load.getControl()?

  12. #12
    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
    Tu dois faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    root = loader.load();
     
    [...]
     
    ControlRechercheFichier r = loader.<ControlRechercheFichier>getController();
    r.remplirList();
    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

  13. #13
    Membre à l'essai
    Homme Profil pro
    dev
    Inscrit en
    Octobre 2020
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Octobre 2020
    Messages : 25
    Points : 16
    Points
    16
    Par défaut
    Merci beaucoup ça fonctionne (j'avais bien dit que c'était un truc aussi bête xD merci en tout cas bouye je mes en résolu)

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 12/12/2008, 08h57
  2. [Language]Constructeur==> Null pointer?
    Par Chiwawa dans le forum Langage
    Réponses: 8
    Dernier message: 14/05/2005, 22h51
  3. Faire pointer sur un objet formulaire
    Par bigsister dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 26/11/2004, 16h25
  4. pointer sur une ligne d'un TStringGrid
    Par jeannot27 dans le forum C++Builder
    Réponses: 7
    Dernier message: 20/10/2004, 10h56
  5. Pointer sur un fichier FILE *
    Par Biou Pink Powa dans le forum C
    Réponses: 3
    Dernier message: 29/01/2004, 14h45

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