Bonsoir
cet exception me gène vraiment,j'ai passé des heures à résoudre mais sans résultat
l'exception:
java.lang.NullPointerException
at java2015.AuthentificationClient$2.actionPerformed(AuthentificationClient.java:122)
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)
le morceau du code qui déclenche l'exception est celui là apparemment:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
                       stX.setString(1, s1);
                                 stX.setString(2, s2);
                                 stX.setString(3, s3);
                                 stX.setString(4,"client");
                                 stX.executeUpdate();
le code entier:
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package java2015;
 
import java.awt.Color;
 
public class AuthentificationClient extends JFrame {
 
	/**
         * 
         */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	static String s3;
	static String s6;
	private JTextField textField_1;
	private JPasswordField passwordField_1;
	Boolean exist;
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AuthentificationClient frame = new AuthentificationClient();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * Create the frame.
         */
	public AuthentificationClient() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 786, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
 
		textField = new JTextField();
		textField.setColumns(10);
 
		JButton btnNewButton = new JButton("Continuer");
		btnNewButton.addActionListener(new ActionListener() {
			@SuppressWarnings("null")
			public void actionPerformed(ActionEvent e) {
 
				String s1=textField_1.getText();
				@SuppressWarnings("deprecation")
				String s2=passwordField_1.getText();
 
				String s4=textField.getText();
				@SuppressWarnings("deprecation")
				String s5=passwordField.getText();
 
				s3=s1+s2;
 
				Connexion c=new Connexion();
				Connection conn=null;
				Statement stat1=null;
				ResultSet res=null;
 
     try {
					if (!(s4.isEmpty()) &&  !(s5.isEmpty())){
						c.Connexion();
		                conn=c.getConnect();
    				String  sql1="SELECT Password FROM gestion_aeroport.utilisateurs WHERE Login='"+s4+"'";
                    stat1= (Statement) conn.createStatement();
                    res = stat1.executeQuery(sql1);
 
            			if(res.next())
            			 {
            			 String motDePasse = res.getString(1);
            			 if(motDePasse.equals(s5))
            			 {
            				 JOptionPane.showMessageDialog(null,"Connexion réussie ! ","Success",JOptionPane.PLAIN_MESSAGE);
             				EspaceClient espClient = new EspaceClient();
            				espClient.setVisible(true);	 
            			 }
 
 
            				 else {
            				 JOptionPane.showMessageDialog(null,"Mot de passe incorrect ! ","Error",1);}
            			 }
 
            				 else {
            				 JOptionPane.showMessageDialog(null,"Login incorrect ! ","Error",1);
            				 }
 
					}
 
 
            			else if (!(s1.isEmpty()) && !(s2.isEmpty()))
 
            			{
 
            				c.Connexion();
                            conn=c.getConnect();
            				Statement statX=null;
            				ResultSet resX=null;
            				PreparedStatement stX=null;
 
            				String  sqlX="SELECT Password FROM gestion_aeroport.utilisateurs WHERE Login='"+s1+"'";
                            statX= (Statement) conn.createStatement();
                            resX = statX.executeQuery(sqlX);
                			if(resX.next())
                			 {
                			 String motDePasseX = resX.getString(1);
                			 if(motDePasseX.equals(s2))
                			 {
                				 JOptionPane.showMessageDialog(null,"Login existant! ","Error",JOptionPane.PLAIN_MESSAGE);
 
                			 }
                			else {
                				 JOptionPane.showMessageDialog(null,"Compte crée ! ","Success",1);
                                 stX.setString(1, s1);
                                 stX.setString(2, s2);
                                 stX.setString(3, s3);
                                 stX.setString(4,"client");
                                 stX.executeUpdate();
                   				EspaceClient espClient = new EspaceClient();
                 				espClient.setVisible(true);	
                 				 }
 
                			 }   
 
 
                    }
 
			}
            catch (Exception e1) {
        	e1.printStackTrace();
            }
			}
 
		});
 
		JLabel lblNewLabel = new JLabel("Login:");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
 
		JLabel lblNewLabel_1 = new JLabel("Mot de passe :");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
 
		passwordField = new JPasswordField();
 
		JLabel lblNewLabel_2 = new JLabel("Acc\u00E8s membre");
		lblNewLabel_2.setForeground(new Color(255, 0, 0));
		lblNewLabel_2.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 14));
 
		textField_1 = new JTextField();
		textField_1.setColumns(10);
 
		JLabel label = new JLabel("Login:");
		label.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
 
		JLabel label_1 = new JLabel("Mot de passe:");
		label_1.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
 
		JLabel lblNouveauMembre = new JLabel("Nouveau membre");
		lblNouveauMembre.setForeground(Color.RED);
		lblNouveauMembre.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 14));
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				ColumnSpec.decode("81px"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("223px"),
				ColumnSpec.decode("32px"),
				ColumnSpec.decode("79px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("78px"),
				ColumnSpec.decode("18px"),
				ColumnSpec.decode("221px:grow"),},
			new RowSpec[] {
				FormFactory.PARAGRAPH_GAP_ROWSPEC,
				RowSpec.decode("25px"),
				FormFactory.PARAGRAPH_GAP_ROWSPEC,
				RowSpec.decode("23px"),
				RowSpec.decode("32px"),
				RowSpec.decode("20px"),
				RowSpec.decode("80px"),
				RowSpec.decode("23px"),}));
		contentPane.add(label_1, "8, 6, left, center");
		contentPane.add(lblNouveauMembre, "10, 2, center, fill");
		contentPane.add(lblNewLabel, "2, 4, fill, center");
		contentPane.add(textField, "4, 4, fill, bottom");
		contentPane.add(label, "8, 4, fill, center");
		contentPane.add(textField_1, "10, 4, fill, top");
		contentPane.add(lblNewLabel_1, "2, 6, left, center");
		contentPane.add(passwordField, "4, 6, fill, top");
 
		passwordField_1 = new JPasswordField();
		contentPane.add(passwordField_1, "10, 6, fill, default");
		contentPane.add(btnNewButton, "6, 8, left, top");
		contentPane.add(lblNewLabel_2, "4, 2, center, fill");
	}
  public static String	idActuel(){
	return s3;
}
}
code la Class Connexion:
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
package java2015;
 
import java.sql.DriverManager;
import java.sql.ResultSet;
 
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
 
public class Connexion {
 
	public static Connection cnx;
 
	public void Connexion(){
			try
			 {
			Class.forName("com.mysql.jdbc.Driver");
			 }
			catch(Exception ex)
			 { 
			System.out.print("Erreur de Chargement");
			System.exit(0);
			 }
			try
			 {
			String url = "jdbc:mysql://localhost:3306/gestion_aeroport";
			String user = "root";
			String passwd = "";
 
			cnx = (Connection) DriverManager.getConnection(url, user, passwd);
			System.out.println("connexion établie");
			 }
			catch(Exception ex)
			 {
			   System.out.print("Erreur de connexion à la BD !!! ");
			 }
	}
			public Connection getConnect()
			{
			return cnx;
			}
 
			public void DeconnexionBD()
			{
			try {
			cnx.close();
			}
			catch(Exception ex) {
			System.out.print("Déconnexion impossible");
			}
		}
 
}