Bonjour je réalise un petit programme pour apprendre java mais voila j ai un petit message d'erreur :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at exemple8$MyActionListener.actionPerformed(exemple8.java:39)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(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.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(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 voici mon programme


Code java : 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
 
public class exemple8 
{
    private int count = 0;
    private JLabel label;
 
    public exemple8() 
    {
        JFrame frame = new JFrame("exemple");
        JButton button = new JButton("clic clic");
 
        button.addActionListener(new MyActionListener());
 
        JLabel label = new JLabel("0");
        JPanel pane = new JPanel();
 
        pane.add(button);
        pane.add(label);
 
        frame.getContentPane().add(pane, BorderLayout.CENTER);
 
        frame.pack();
 
        frame.setVisible(true);
    }
    /* on peut écrire une class à l'intérieur d'une autre, */
    /* utilisée uniquement dans la classe englobante. */
 
    private class MyActionListener implements ActionListener 
    {
        public void actionPerformed(ActionEvent event) 
        {
            count++;
            label.setText(Integer.toString(count));
        }
    }
 
    public static void main(String[] args) 
    {
        new exemple8();
    }
 
}

Et apparement l'erreur viendrait de la ligne 39 soit :

label.setText(Integer.toString(count));

Vraiment besoins d aide svpp