Alors voici, j'ai une erreur de type NullPointerException, lorsque j'ajoute un nouveau nœud à mon JTree. Cela arrive environ une fois sur 4.
Ce JTree est destiné à filtrer les courbes représentés sur un graphique du type JFreeChart. Hélas, je ne comprends pas du tout d'où cela peut-il venir.

L'Erreur :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
----
at javax.swing.plaf.basic.BasicTreeUI.completeEditing(BasicTreeUI.java:2009)
at javax.swing.plaf.basic.BasicTreeUI.completeEditing(BasicTreeUI.java:1974)
at javax.swing.plaf.basic.BasicTreeUI$Handler.valueChanged(BasicTreeUI.java:3637)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
at javax.swing.tree.DefaultTreeSelectionModel.clearSelection(DefaultTreeSelectionModel.java:570)
at javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:740)
at javax.swing.tree.VariableHeightLayoutCache.treeStructureChanged(VariableHeightLayoutCache.java:626)
at javax.swing.plaf.basic.BasicTreeUI$Handler.treeStructureChanged(BasicTreeUI.java:3824)
at javax.swing.tree.DefaultTreeModel.fireTreeStructureChanged(DefaultTreeModel.java:561)
at javax.swing.tree.DefaultTreeModel.nodeStructureChanged(DefaultTreeModel.java:347)
at javax.swing.tree.DefaultTreeModel.setRoot(DefaultTreeModel.java:117)
at InterfaceGraphique.Tree.updateTree(Tree.java:102)
at InterfaceGraphique.View.constructFile(View.java:515)
at InterfaceGraphique.View.jMenuItem1ActionPerformed(View.java:375)
at InterfaceGraphique.View.access$000(View.java:51)
at InterfaceGraphique.View$4.actionPerformed(View.java:174)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


View :
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
public class View extends javax.swing.JFrame{ --> L51
 
 
private void initComponents() {
 
....
 
 
JButton addFile = new JButton();
        addFile.setMaximumSize(new Dimension(20, 20));
        addFile.setText("+");
        addFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) { L174
                jMenuItem1ActionPerformed(evt);
            }
        });
 
....
 
 JScrollPane treeview = tree.createTree();
        treeview.setMinimumSize(new Dimension(0, 600));
        treeview.setPreferredSize(new Dimension(200, 600));  
        splitPane.setLeftComponent(treeview);
 
....
 
}
 
 
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
        JFileChooser chooser = new JFileChooser();
        FileFilter filter = new FileFilter() {
            public boolean accept(File pathname) {
                if (pathname.isDirectory()) {
                    return true;
                }
                String extension = getExtension(pathname);
                if (extension != null) {
                    return true;
                }
                return false;
             }
             public String getExtension(File f) {
                String ext = null;
                String s = f.getName();
                int i = s.lastIndexOf('.');
 
                if (i > 0 &&  i < s.length() - 1) {
                    ext = s.substring(i+1).toLowerCase();
                }
                return ext;
            }
 
            @Override
            public String getDescription() {
                return "Tout type de fichier";
            }
        };
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            this.parseur = new Parseur(chooser.getSelectedFile().getPath());
            constructFile(this.parseur.parseFile()); -->375
        }
}
 
....
 
public void constructFile(Vector<Fnct> fnct){
 
        Fichier file = new Fichier(fnct);
        Position(file);        
        this.Fichiers.add(file);
        int variable = this.Fichiers.size()-1;
        file.setCouleur(new Color((100*variable)%255, (150*variable)%255, (200*variable)%255));
        String pathfile = this.parseur.getpathfile();
        if(this.comboisInit == false){
             comboInit();
        }
        this.tree.updateTree(fnct.size(), pathfile, file); --> 515
        AffData();
}
 
} //end of class view
 
 
public class Tree {
 
    private JTree tree;
    private DefaultMutableTreeNode root;
    DefaultMutableTreeNode files;
    int nbFnct;
    private View parent;
 
     public Tree(View parent){
         this.parent = parent;
     }
 
     public JScrollPane createTree(){
 
        tree = new JTree();
 
        root = new DefaultMutableTreeNode(new String("Fichiers"));
        tree = new JTree(root);
 
        Tree_rendu tr = new Tree_rendu();
        //DefaultTreeCellRenderer Tree_rendu;
        Tree_edit te = new Tree_edit();
 
        tree.setCellRenderer(tr);
        //Tree_rendu = (DefaultTreeCellRenderer) tree.getCellRenderer();
        tree.setCellEditor(te);
        tree.setEditable(true);
 
        JScrollPane jsp = new JScrollPane(tree);
        //this.add(jsp);
        return jsp;
 
     }
 
     public void updateTree(int nbFnct, String pathfile, Fichier fichier){
 
         this.nbFnct = nbFnct;
         Vector<DefaultMutableTreeNode> temp = new Vector();
 
         for (int row = 0; row < this.root.getChildCount() ; row++) {
            temp.add((DefaultMutableTreeNode)this.root.getChildAt(row));
         }
 
         String[] tempFile = pathfile.split("/");
 
         chkbox jcb_files = new chkbox(fichier.getDisplayFile(), fichier, -1, new File(pathfile).getName());
         files = new DefaultMutableTreeNode(jcb_files, true);
         jcb_files.setSelected(true);
 
         Vector<chkbox> chkboxes = new Vector();
         for(int compteur=0; compteur < nbFnct; compteur++){
                int num = compteur + 1;
                chkbox jcb_fnct = new chkbox(fichier.getDisplayFnct().get(compteur), fichier, compteur, new String("Fonction " + num));
                jcb_fnct.setSelected(true);
 
                jcb_fnct.addActionListener(new java.awt.event.ActionListener(){
                    public void actionPerformed(java.awt.event.ActionEvent e){
                        filtre((chkbox)e.getSource());
                    }
                });
 
                chkboxes.add(jcb_fnct);
                DefaultMutableTreeNode fnct = new DefaultMutableTreeNode(jcb_fnct, true);
                files.add(fnct);
         }
 
         fichier.setCheckBox(chkboxes);
         this.root.add(files);
         ((DefaultTreeModel) this.tree.getModel()).setRoot(this.root); -->L102
         ((DefaultTreeModel) this.tree.getModel()).reload();
 
         jcb_files.addActionListener(new java.awt.event.ActionListener(){
              public void actionPerformed(java.awt.event.ActionEvent e){
                  filtre((chkbox)e.getSource());
              }
         });
 
         tree.repaint();
         //this.tree.validate();
     }
 
     public void filtre(chkbox  chkbox){
        if(chkbox.isSelected() == true){
             chkbox.setEnable();
         }
         else{
             chkbox.setDisable();
         }
         this.parent.AffData();
         this.tree.repaint();
     }
 
} // end of class Tree

Si quelqu'un pouvait m'aider à débusquer mon problème ce serait sympa.