Bonsoir,

J'ai ce message d'erreur :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at application.login.jButton2ActionPerformed(login.java:83)
at application.login.access$100(login.java:13)
at application.login$2.actionPerformed(login.java:73)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:740)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:699)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:713)
at java.awt.EventQueue$4.run(EventQueue.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:710)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) 

Voici mon code :


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
package application;
 
 
 
 
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
 
 
public class login extends javax.swing.JFrame {
 
ResultSet rs ;
DBB db ; 
String username1,password1,hak;
 
public login() {
 
 
initComponents();
}
 
 
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code"> 
private void initComponents() {
 
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
TXT2 = new javax.swing.JTextField();
TXT1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
 
jLabel1.setFont(new java.awt.Font("Sylfaen", 1, 36)); // NOI18N
jLabel1.setForeground(new java.awt.Color(102, 102, 255));
jLabel1.setText("Login");
getContentPane().add(jLabel1);
jLabel1.setBounds(147, 37, 179, 48);
 
jLabel2.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
jLabel2.setText("username");
getContentPane().add(jLabel2);
jLabel2.setBounds(32, 98, 103, 22);
 
jLabel3.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
jLabel3.setText("Password ");
getContentPane().add(jLabel3);
jLabel3.setBounds(32, 155, 103, 37);
 
TXT2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
TXT2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TXT2ActionPerformed(evt);
}
});
getContentPane().add(TXT2);
TXT2.setBounds(170, 160, 140, 29);
 
TXT1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
getContentPane().add(TXT1);
TXT1.setBounds(172, 96, 140, 29);
 
jButton2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jButton2.setText("Login");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(60, 230, 100, 31);
 
pack();
}// </editor-fold> 
 
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { 
rs = db.QselectAll("Untitled","username='"+TXT1.getText()+"'and password='"+TXT2.getText()+"'");
try{
while(rs.next()){
username1 = rs.getString("username");
password1 = rs.getString("password");
hak = rs.getString("type");
}}catch(SQLException ex){
Logger.getLogger(login.class.getName()).log(Level.SEVERE,null ,ex);
 
}
if(username1 == null && password1 == null){
 
JOptionPane.showMessageDialog(this,"le non utilisateur ou le mots pass est inncorrect");
 
}else{
if(hak.equals("admin")){
principal h =new principal();
h.setVisible(true);
this.dispose();
}else{
principal2 k = new principal2();
k.setVisible(true);
this.dispose();
 
 
}
 
}
 
 
 
 
 
} 
 
private void TXT2ActionPerformed(java.awt.event.ActionEvent evt) { 
// TODO add your handling code here:
} 
 
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see <a href="http://download.oracle.com/javase/tu...feel/plaf.html" target="_blank">http://download.oracle.com/javase/tu...feel/plaf.html</a> 
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
 
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login().setVisible(true);
}
});
}
 
// Variables declaration - do not modify 
private javax.swing.JTextField TXT1;
private javax.swing.JTextField TXT2;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration 
 
private static class Principal {
 
public Principal() {
}
 
private void setVisible(boolean b) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
}