Précédent   Forum du club des développeurs et IT Pro > Java > EDI et OUTILS pour Java > NetBeans
NetBeans Forum d'entraide NetBeans. Avant de poster -> Ressources NetBeans - La F.A.Q NetBeans - Tutoriels NetBeans
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 09/01/2013, 16h33   #1
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
Par défaut PropertyChange d'un jDateChooser

Salut tout le monde,
J'ai un problème que je le comprends pas j'ai utilisé le PropertyChange d'un jDateChooser en netBens pour lancer un traitement en récupérant la date sélectionner mais ca m'envoie une erreur la voici :
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
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Courrier.ModifierCourrier.jDateChooser1PropertyChange(ModifierCourrier.java:301)
        at Courrier.ModifierCourrier.access$100(ModifierCourrier.java:30)
        at Courrier.ModifierCourrier$2.propertyChange(ModifierCourrier.java:108)
        at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
        at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
        at java.awt.Component.firePropertyChange(Component.java:8163)
        at javax.swing.JComponent.addNotify(JComponent.java:4686)
        at java.awt.Container.addNotify(Container.java:2576)
        at javax.swing.JComponent.addNotify(JComponent.java:4685)
        at java.awt.Container.addNotify(Container.java:2576)
        at javax.swing.JComponent.addNotify(JComponent.java:4685)
        at java.awt.Container.addNotify(Container.java:2576)
        at javax.swing.JComponent.addNotify(JComponent.java:4685)
        at java.awt.Container.addNotify(Container.java:2576)
        at javax.swing.JComponent.addNotify(JComponent.java:4685)
        at javax.swing.JRootPane.addNotify(JRootPane.java:738)
        at java.awt.Container.addNotify(Container.java:2576)
        at java.awt.Window.addNotify(Window.java:662)
        at java.awt.Frame.addNotify(Frame.java:470)
        at java.awt.Window.pack(Window.java:703)
        at Courrier.ModifierCourrier.initComponents(ModifierCourrier.java:244)
        at Courrier.ModifierCourrier.<init>(ModifierCourrier.java:35)
        at Courrier.ModifierCourrier$4.run(ModifierCourrier.java:374)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
        at java.awt.EventQueue.access$000(EventQueue.java:84)
        at java.awt.EventQueue$1.run(EventQueue.java:607)
        at java.awt.EventQueue$1.run(EventQueue.java:605)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
        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)

et même avant que la fenêtre apparaisse???????????
SVP aidez-moi merci d’avance
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/01/2013, 21h22   #2
plegat
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 3 239
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 3 239
Points : 5 553
Points : 5 553
Salut

Code :
java.lang.NullPointerException... ModifierCourrier.java:301
Null pointer exception... ligne 301... là est la réponse...
__________________
"Errare humanum est, sed perseverare diabolicum"

Ma page sur DVP.com
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/01/2013, 09h30   #3
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
Oui je comprend que ma variable est null « Date d=jDateChooser1.getDate() ; » mais pourquoi il va au traitement avant exécuter la jFrame et faire entrer la date par le jDateChooser
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/01/2013, 10h45   #4
plegat
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 3 239
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 3 239
Points : 5 553
Points : 5 553
Citation:
Envoyé par InfOCynO Voir le message
Oui je comprend que ma variable est null « Date d=jDateChooser1.getDate() ; » mais pourquoi il va au traitement avant exécuter la jFrame et faire entrer la date par le jDateChooser
Parce que tu as dû le lui demander dans ton code...
Par exemple en ligne 244 de ta classe ModifierCourrier.
Quand tu as une erreur comme ça, il faut analyser la stack trace. Ce n'est pas pour rien que le message d'erreur te renvoie tout l'historique des appels de méthodes, ça te permet de naviguer dans ton code pour voir par où est passé ton programme, et bien comprendre ce qui s'est passé.

Bon, après, vu que tu ne donnes pas de code, on te laisse chercher dans tes fichiers source!
__________________
"Errare humanum est, sed perseverare diabolicum"

Ma page sur DVP.com
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/01/2013, 11h54   #5
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
Merci pour ta réponse plegat
Voici mon code :
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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package Courrier;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
 
/**
 *
 * @author developpeur
 */
public class ModifierCourrier extends javax.swing.JFrame{
 
    /** Creates new form ModifierCourrier */
    public ModifierCourrier() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, SQLException {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        initComponents();
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
 
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
                con = DriverManager.getConnection(url);
 
 
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        textField1 = new java.awt.TextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        textField2 = new java.awt.TextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
 
        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Consulter Courrier");
 
        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Numéro du courrier :");
 
        textField1.addTextListener(new java.awt.event.TextListener() {
            public void textValueChanged(java.awt.event.TextEvent evt) {
                textField1TextValueChanged(evt);
            }
        });
 
        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Date du courrier  :");
 
        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Emetteur :");
 
        jComboBox1.setEditable(true);
 
        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Destinataire :");
 
        jComboBox2.setEditable(true);
 
        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Réponse de :");
 
        jComboBox3.setEditable(true);
 
        jDateChooser1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jDateChooser1PropertyChange(evt);
            }
        });
        jDateChooser1.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jDateChooser1VetoableChange(evt);
            }
        });
 
        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Liste des courriers :", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
 
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Numéro", "Date", "Objet"
            }
        ));
        jScrollPane1.setViewportView(jTable1);
 
        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setText("A comme reponse  :");
 
        jButton1.setText("AFFICHER");
 
        jButton2.setText("IMPRIMER");
 
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(2, 2, 2))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jComboBox3, 0, 147, Short.MAX_VALUE)
                                        .addGap(2, 2, 2))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jComboBox2, 0, 147, Short.MAX_VALUE)
                                        .addGap(2, 2, 2))
                                    .addComponent(jComboBox1, 0, 147, Short.MAX_VALUE)
                                    .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                                    .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(41, 41, 41)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(273, 273, 273)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
 
        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jComboBox1, jComboBox2, jComboBox3, jDateChooser1, textField1, textField2});
 
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textField1, 0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textField2, 0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
 
        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jComboBox1, jComboBox2, jComboBox3, jDateChooser1, textField1, textField2});
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
 
        pack();
    }// </editor-fold>
 
    private void textField1TextValueChanged(java.awt.event.TextEvent evt) {                                            
 
 
            String t = textField1.getText();
            System.out.println(t.toString());
            String query = "SELECT [numero_courrier],[date_courrier],[objet] FROM [GestionCourrier].[dbo].[courrier] where (numero_courrier like '"+t+"%')";
 
                try {
                     java.sql.Statement stmt = con.createStatement();
 
                     ResultSet rs=stmt.executeQuery(query);
                     int i=1;
                     DefaultTableModel model = new DefaultTableModel();
                    // model.setColumnCount(3);
                     model.addColumn("Numéro");
                     model.addColumn("Date");
                     model.addColumn("Objet");
                     jTable1.setModel(model);
 
 
                    while(rs.next()){
                        String num=rs.getString(1);
                        String date=rs.getString(2);
                        String objet=rs.getString(3);
                       model.setRowCount(i);
                       jTable1.setValueAt(num, i-1,0);
                       jTable1.setValueAt(date, i-1, 1);
                       jTable1.setValueAt(objet, i-1,2);
                       i++;
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                }
 
 
 
            // TODO add your handling code here:
    }                                           
 
    private void jDateChooser1VetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {                                             
 
// TODO add your handling code here:
    }                                            
 
    private void jDateChooser1PropertyChange(java.beans.PropertyChangeEvent evt) {                                             
 
          try {
 
            Date d=jDateChooser1.getDate();
            java.sql.Date dsql= new java.sql.Date(d.getTime());
            String query="SELECT [numero_courrier],[date_courrier],[objet] FROM [GestionCourrier].[dbo].[courrier] where date_courrier='"+dsql+"'";
            java.sql.Statement stmt = con.createStatement();
            ResultSet rs=stmt.executeQuery(query);
            int i=1;
            DefaultTableModel model = new DefaultTableModel();
            // model.setColumnCount(3);
            model.addColumn("Numéro");
            model.addColumn("Date");
            model.addColumn("Objet");
            jTable1.setModel(model);
            while(rs.next()){
 
            model.setRowCount(i);
            jTable1.setValueAt(rs.getString(1), i-1,0);
            jTable1.setValueAt(rs.getString(2), i-1, 1);
            jTable1.setValueAt(rs.getString(3), i-1,2);
            i++;
            }
 
            // TODO add your handling code here:
            } catch (SQLException ex) {
            Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
            }
            // TODO add your handling code here:
 
 
 
                   // TODO add your handling code here:
    }                                            
 
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
 
                    try {
                        new ModifierCourrier().setVisible(true);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InstantiationException ex) {
                        Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IllegalAccessException ex) {
                        Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (UnsupportedLookAndFeelException ex) {
                        Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
                    }
 
            }
        });
 
    }
                      private  Connection con = null;
                          private   String url = "jdbc:sqlserver://localhost:49163;databaseName=GestionCourrier;integratedSecurity=true;";
 
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private java.awt.TextField textField1;
    private java.awt.TextField textField2;
    // End of variables declaration
 
 
 
}
mais c'est le netBeans qui génère le code ???
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/01/2013, 13h24   #6
plegat
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 3 239
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 3 239
Points : 5 553
Points : 5 553
Citation:
Envoyé par plegat Voir le message
Null pointer exception... ligne 301... là est la réponse...
Citation:
Envoyé par InfOCynO Voir le message
Oui je comprend que ma variable est null « Date d=jDateChooser1.getDate() ; »
Euh... ligne 301, il y a un:

Code :
1
2
 
jTable1.setValueAt(rs.getString(2), i-1, 1);
(qui ne me semblerait pas lancer un null pointer exception vu le contexte...)

C'est quoi le bon code?



Citation:
Envoyé par InfOCynO Voir le message
mais c'est le netBeans qui génère le code ???
pas celui que tu tapes...
Netbeans génère automatiquement le code GUI à partir de ce que tu lui demandes de faire de toute façon, il ne fait pas de la génération automatique raisonnée en fonction des souhaits du programmeur.
Donc même si Netbeans génère quelque chose, c'est toujours de ta responsabilité de vérifier quand ça ne fonctionne pas comme tu le souhaites.
__________________
"Errare humanum est, sed perseverare diabolicum"

Ma page sur DVP.com
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/01/2013, 11h40   #7
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
Me revoici plegat, j'ai recherché encore sur internet mais je n'ai pas trouvé une solution parce que même si je mets que cela :
Code :
1
2
3
4
5
private void jDateChooser1PropertyChange(java.beans.PropertyChangeEvent evt) {                                             
 
            Date d=jDateChooser1.getDate();
           System.out.println(d.toString());
}
J’aurais la même erreur nullPointerException
SVP encore un aide
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/01/2013, 10h20   #8
plegat
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 3 239
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 3 239
Points : 5 553
Points : 5 553
Citation:
Envoyé par InfOCynO Voir le message
SVP encore un aide
J'ai posé une question jsute au-dessus, je veux bien t'aider, mais sans répondre aux questions, ce n'est pas facile...

Quelle est la ligne qui déclenche l'erreur?
Quel est l'objet qui est null?

A partir du moment où tu as une nullPointerException qui se déclenche, il faut chercher à comprendre qui et pourquoi, et modifier ton algo en fonction. Tu appelles des méthodes sur des objets, dont un qui est null, sans précautions... donc soit tu t'assures que ça n'arrive jamais, soit tu gères la situation quand ça arrive...
__________________
"Errare humanum est, sed perseverare diabolicum"

Ma page sur DVP.com
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/01/2013, 13h35   #9
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
l’erreur vient de la ligne :
Code :
System.out.println(d.toString());
quant j'ai met
Code :
1
2
private void jDateChooser1PropertyChange(java.beans.PropertyChangeEvent evt) {        System.out.println("Moi"); // TODO add your handling code here:
    }
Le « Moi » s'affiche avant l'apparaissions de la fenêtre puis j'ai ma fenêtre et à chaque fois que je change la date le « Moi» se réaffiche d'après ca je comprends que la 1iere exécution de jDateChooser1PropertyChange se fait avant que je la donne une valeur et pour cela j'ai le NullPointer donc j'ai essayé ca :
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
 private void jDateChooser1PropertyChange(java.beans.PropertyChangeEvent evt) {                                             
       Date dj=new Date();
        if(d.equals(dj)){
        System.out.println("1iere execution");
 
        }
        else{
        try {
             d=jDateChooser1.getDate();
            System.out.println(d.toString());
            java.sql.Date dsql= new java.sql.Date(d.getTime());
            String query="SELECT [numero_courrier],[date_courrier],[objet] FROM [GestionCourrier].[dbo].[courrier] where date_courrier='"+dsql+"'";
            java.sql.Statement stmt = con.createStatement();
            ResultSet rs=stmt.executeQuery(query);
            int i=1;
            DefaultTableModel model = new DefaultTableModel();
            //model.setColumnCount(3);
            model.addColumn("Numéro");
            model.addColumn("Date");
            model.addColumn("Objet");
            jTable1.setModel(model);
            while(rs.next()){
            String num=rs.getString(1);
            String date=rs.getString(2);
            String objet=rs.getString(3);
            model.setRowCount(i);
            jTable1.setValueAt(num, i-1,0);
            jTable1.setValueAt(date, i-1, 1);
            jTable1.setValueAt(objet, i-1,2);
            i++;
            }
            // TODO add your handling code here:
            } catch (SQLException ex) {
            Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
            }   }     // TODO add your handling code here:
    }
mais ca marche pas il n’entre pas au if et l’erreur provient tjrs de:
Code :
System.out.println(d.toString());
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/01/2013, 14h46   #10
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
la SolUtion, je ne pense pas qu'elle est la meilleure mais ca marche
j'ai déclaré ma variable :
Code :
private Date d=new Date(WIDTH);
Et voici la méthode :
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
    private void jDateChooser1PropertyChange(java.beans.PropertyChangeEvent evt) {                                             
        try {
            String ds = datetostring(d);
            Date dj=new Date(WIDTH);
            String djs = datetostring(dj);
 
 
 
        if(ds.equals(djs)){
        System.out.println("1iere execution");
          d=new Date();
        }
        else{
        try {
             d=jDateChooser1.getDate();
            System.out.println(d.toString());
            java.sql.Date dsql= new java.sql.Date(d.getTime());
            String query="SELECT [numero_courrier],[date_courrier],[objet] FROM [GestionCourrier].[dbo].[courrier] where date_courrier='"+dsql+"'";
            java.sql.Statement stmt = con.createStatement();
            ResultSet rs=stmt.executeQuery(query);
            int i=1;
            DefaultTableModel model = new DefaultTableModel();
            //model.setColumnCount(3);
            model.addColumn("Numéro");
            model.addColumn("Date");
            model.addColumn("Objet");
            jTable1.setModel(model);
            while(rs.next()){
            String num=rs.getString(1);
            String date=rs.getString(2);
            String objet=rs.getString(3);
            model.setRowCount(i);
            jTable1.setValueAt(num, i-1,0);
            jTable1.setValueAt(date, i-1, 1);
            jTable1.setValueAt(objet, i-1,2);
            i++;
            }
            } catch (Exception ex) {
            Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
        }}
            // TODO add your handling code here:
                } catch (Exception ex) {
            Logger.getLogger(ModifierCourrier.class.getName()).log(Level.SEVERE, null, ex);
        }  // TODO add your handling code here:
    }
et merci comme même plegat
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/01/2013, 19h40   #11
plegat
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 3 239
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 3 239
Points : 5 553
Points : 5 553
Citation:
Envoyé par InfOCynO Voir le message
l’erreur vient de la ligne :
Code :
System.out.println(d.toString());
Citation:
Envoyé par InfOCynO Voir le message
la SolUtion, je ne pense pas qu'elle est la meilleure mais ca marche
Personnellement, j'aurais juste mis un:

Code :
1
2
3
4
 
if (d!=null) {
...
}
c'est plus simple...
__________________
"Errare humanum est, sed perseverare diabolicum"

Ma page sur DVP.com
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/01/2013, 11h08   #12
InfOCynO
Futur Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 66
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 66
Points : 17
Points : 17
plus simple,si sûr
merci encore une fois
InfOCynO est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 01h16.


 
 
 
 
Partenaires

Hébergement Web