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

AWT/Swing Java Discussion :

Exception in thread "AWT-EventProblème: Queue-0" java.lang.NullPointerException


Sujet :

AWT/Swing Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    213
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 213
    Points : 43
    Points
    43
    Par défaut Exception in thread "AWT-EventProblème: Queue-0" java.lang.NullPointerException
    Bonjour, déjà, désolé si je ne suis pas dans la bonne partie.

    Alors voilà, j'ai une fenêtre en java avec des arbres et des listener pour ces arbres. Jusque là pas de problèmes je lance l'appli et qlique sur le composant d'un arbre, et là gros problème:
    Il m'affiche une erreur:
    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
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at GUI.fenetre_serveur$connection_listener.valueChanged(fenetre_serveur.java:83)
    	at javax.swing.JTree.fireValueChanged(Unknown Source)
    	at javax.swing.JTree$TreeSelectionRedirector.valueChanged(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(Unknown Source)
    	at javax.swing.JTree.setSelectionPath(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Et bizarrement il m'ouvre une nouvelle fenetre...

    Voici le code complet de la fenetre
    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
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    package GUI;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import java.awt.*;
     
    import java.io.*;
    import java.util.*;
     
     
    public class fenetre_serveur extends JFrame{
     
    	static JTree tree_cmd;
    	static JTree tree_clients;
    	JPanel panel_final;
    	BorderLayout layout_final;
    	JLabel afficheur;
    	JTabbedPane onglet;
    	JSplitPane split;
     
    	static Hashtable clients_table; //la table de hach qui contiendra la correspondance ip/buffer
    	//static commande cmd;
     
    	public fenetre_serveur() {
     
    		clients_table = new Hashtable();
     
    		this.setTitle("serveur_Okami");
    		this.setSize(500, 350);
    		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		this.setLocationRelativeTo(null);
     
    		//INTERFACE DE COMMANDE
    		DefaultMutableTreeNode racine = new DefaultMutableTreeNode("Commandes");
    		DefaultMutableTreeNode capture = new DefaultMutableTreeNode("capture");
    		racine.add(capture);
    		DefaultMutableTreeNode exec = new DefaultMutableTreeNode("terminal");
    		racine.add(exec);
    		DefaultMutableTreeNode keyboard = new DefaultMutableTreeNode("key");
    		racine.add(keyboard);
    		DefaultMutableTreeNode mouse = new DefaultMutableTreeNode("mouse");
    		racine.add(mouse);
    		DefaultMutableTreeNode file = new DefaultMutableTreeNode("file");
    		racine.add(file);
    		tree_cmd = new JTree(racine);
     
    		//INTERFACE CLIENTE
    		DefaultMutableTreeNode clients = new DefaultMutableTreeNode("Clients");
    		tree_clients = new JTree(clients);
     
    		//LES LISTENER
    		tree_clients.addTreeSelectionListener(new connection_listener());
    		tree_cmd.addTreeSelectionListener(new cmd_listener());
     
    		//PANEL PRINCIPAL
    		split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tree_cmd, tree_clients);
    		split.setPreferredSize(new Dimension(250, 250));
     
    		//PANEL FINAL
    		panel_final = new JPanel();
    		layout_final = new BorderLayout();
    		panel_final.setLayout(layout_final);
    		afficheur = new JLabel("Developped by Okami");
    		panel_final.add(split, BorderLayout.NORTH);
    		panel_final.add(afficheur, BorderLayout.SOUTH);
     
    		onglet = new JTabbedPane();
    		onglet.add(panel_final, "Home");
     
    		this.setContentPane(onglet);
    		this.setVisible(true);
    	}
     
    	//LES LISTENER
     
    	public class connection_listener implements TreeSelectionListener{ //le listener des clients connectes
    		public void valueChanged(TreeSelectionEvent event) {
    			if(tree_clients.getLastSelectedPathComponent() != null){
    				commande cmd = new commande();
    				String adresse = new String();
    				adresse = tree_clients.getLastSelectedPathComponent().toString();
    				cmd.connect(adresse);
    			}
    	}
    }//fin de class connection_listener
     
    	public class cmd_listener implements TreeSelectionListener{ //le listener des commande
    		public void valueChanged(TreeSelectionEvent event) {
    			if(tree_cmd.getLastSelectedPathComponent() != null){
    				commande cmd = new commande();
    				String commande = new String();
    				commande = tree_cmd.getLastSelectedPathComponent().toString();
    				if(commande.equals("Commandes"))
    					return; 
    				else if(commande.equals("terminal")) 
    					cmd.exec_cmd();
    				else
    					cmd.commande_envoie(commande);
    			}
    	}
    	}//fin de class cmd_listener
    }
    Et la ligne qui correspond à l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    commande = tree_cmd.getLastSelectedPathComponent().toString();
    lorsque je clique sur l'arbre des commandes ou

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    adresse = tree_clients.getLastSelectedPathComponent().toString();
    Lorsque je clique sur l'arbre des clients.

    Je sais que le pointeur null exception veut dire qu'une variable est nulle, mais là je ne vois vraiment pas laquelle ça peut être...

    Merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    getLastSelectedPathComponent te retourne vraissemblablement un null.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    213
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 213
    Points : 43
    Points
    43
    Par défaut
    C'est aussi ce que je me suis dit.
    Mais pourquoi ouvre t il aussi une autre fenetre?

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    retire déjà ces static, si t'as deux instances ca va etre le bordel. Ensuite pour la deuxième fenetre, regarde les endroit ou t'appelle le constructeur, t'en a une de trop

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    213
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 213
    Points : 43
    Points
    43
    Par défaut
    Olalala l'erreur stupide, j'instanciais fenetre_serveur une autre fois...

    Merci beaucoup de ton aide

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

Discussions similaires

  1. Réponses: 5
    Dernier message: 24/02/2008, 22h58
  2. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException ?
    Par freezerhm dans le forum Concurrence et multi-thread
    Réponses: 5
    Dernier message: 04/12/2007, 09h26
  3. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par Trint dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 27/02/2007, 11h28
  4. Réponses: 8
    Dernier message: 11/05/2006, 19h32
  5. [JDIC]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par kedare dans le forum Concurrence et multi-thread
    Réponses: 4
    Dernier message: 06/05/2006, 22h45

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