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:
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:
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:
commande = tree_cmd.getLastSelectedPathComponent().toString();
lorsque je clique sur l'arbre des commandes ou
Code:
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