IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Un NullPointerException inexpliquable


Sujet :

Langage Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut Un NullPointerException inexpliquable
    Bonjour, je vous lance un défi : trouver pourquoi j'obtiens un NullPointerException...

    Voici les lignes où ça plante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    buttons = new Button[10];              
    buttons[0].setText("SELECTIONNER");
    Ici les détails de l'exception levée

    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
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at GUI.search.SearchContainer.itemsContructor(SearchContainer.java:102)
            at GUI.search.SearchContainer.<init>(SearchContainer.java:56)
            at engine.Listeners.makeAction(Listeners.java:91)
            at engine.Listeners.<init>(Listeners.java:39)
            at javarch.start.MenuBar.actionPerformed(MenuBar.java:383)
            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.AbstractButton.doClick(AbstractButton.java:357)
            at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1216)
            at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1257)
            at java.awt.Component.processMouseEvent(Component.java:6038)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5803)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4410)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2429)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Et si ça vous intéresse mon fichier

    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
    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
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    public class SearchContainer extends UnderFrame implements ActionListener, DocumentListener, FocusListener{
     
        private String[] labelsButtons = {"COMPLET >>> PARTIEL", "PARTIEL >>> COMPLET", "SUPPRIMER LE CONTENEUR", "SORTIR DE L'EMPLACEMENT", "VOIR", "FERMER"},
                titles;
        private String from;
        private javarch.components.Container container;
        private Object [][] allOfContainer;
        private boolean yes = true;
     
        public SearchContainer (Javarch javarch, String from) {
            super(790, 650, "Recherche de conteneurs", javarch);
            this.setJavarch(javarch);
            this.from = from;
            if (from.equals("search")) {
                String [] tmp = {"NUMERO DE CONTENEUR","EMPLACEMENT", "ETAT"};
                titles = tmp;
            }
            else if (from.equals("location")) {
                String[] tmp = {"NUMERO CONTENEUR", "NOMBRE PRESENTS","EMPLACEMENT"};
                titles = tmp;
                setTitle("Recherche de conteneurs");
            }
            else if (from.equals("storing")) {
                String[] tmp = {"NUMERO DE CONTENEUR","EMPLACEMENT", "NOMBRE PRESENTS","ETAT" };
                titles = tmp;
                this.setTitle("Recherche de conteneur");
            }
            EngineMethods.centerFrame(this);//to center the frame
            itemsContructor(javarch);//create items
            initItems();
            addContain();//add items construted on a panel
            this.getContentPane().add(getMainPanel());
            this.setVisible(yes);
        }
     
        public void itemsContructor(Javarch javarch) {
            final int NBBOX = 6,NBHORIZ = 5, NBFIELDS = 3, NBBUTTONS = 6, NBTABLES =1, NBCKITEM = titles.length-1;
            boxes = new Box[NBBOX];
            fields = new Field[NBFIELDS];
            buttons = new Button[NBBUTTONS];
            tables = new Table[NBTABLES];
            scrolls = new JScrollPane[NBTABLES];
            isSelectedCollumns = new boolean[NBCKITEM+1];
            tableModels = new TableModel[NBTABLES];
            sorter = new TableRowSorter[NBTABLES];
     
            for (int i=0; i<NBBOX; i++) {
                if (i<NBHORIZ) boxes[i] = Box.createHorizontalBox();
                else boxes[i] = Box.createVerticalBox();
            }
     
            for (int i=0; i<NBFIELDS; i++) {
                if(i==0)fields[i]=new Field(5);
                if(i==1)fields[i]=new Field(6);
                if(i==2)fields[i]=new Field(20);
                if(i==3)fields[i]=new Field(6);
                if (i>0) {
                    fields[i].setDisabled();
                }
                else {
                    fields[i].getDocument().addDocumentListener(this);
                    fields[i].addFocusListener(this);
                }
            }
     
            for (int i=0; i<NBBUTTONS; i++) {
                if (from.equals("storing")) {
                    if (i<4) {
                        buttons = new Button[10];
    //                    buttons[i].setVisible(false);
                    }
                    else if (i==4) {
                        buttons = new Button[10];
                        buttons[0].setText("SELECTIONNER");
                    }
                }
                String type = "";
                switch (i) {
                    case 0 : type = "completPartiel";break;
                    case 1 : type = "partielComplet";break;
                    case 2 : type = "deleteContainer";break;
                    case 3 : type = "outOfLocation";break;
                    case 4 : type = "view";break;
                    case 5 : type = "close";break;
                }
                buttons[i] = new Button(labelsButtons[i], type);
                buttons[i].addActionListener(this);
            }
            try {
                tables[0] = createTable();
                scrolls[0] = new JScrollPane(tables[0]);
            }
            catch (SQLException ex) {JOptionPane.showMessageDialog(this, "Impossible de créer la table.\n"+ex.toString(), "Erreur", JOptionPane.ERROR_MESSAGE);}
     
            for(int i=0; i<isSelectedCollumns.length; i++) {
                isSelectedCollumns[i]=true;
            }
     
            isSelectedRows = new boolean[listForTable.length];
            for (int i=0; i<isSelectedRows.length; i++) {
                isSelectedRows[i] = true;
            }
     
            sorter[0] = new TableRowSorter<TableModel>(tableModels[0]);
            MouseAdapter mouseAdapter = new MouseAdapter() {
                public void mouseClicked(MouseEvent m) {
                    if (m.getClickCount() == 2) {
                        actionPerformed(new ActionEvent(buttons[4], 0, ""));
                    }
                    if (m.getButton()==MouseEvent.BUTTON3) {
                        int indRow = tables[0].rowAtPoint(m.getPoint());
                        int indCol = tables[0].columnAtPoint(m.getPoint());
                        tables[0].changeSelection(indRow, indCol, false, false);
     
                        displayPopup(m);
                    }
                }
            };
            tables[0].addMouseListener(mouseAdapter);
        }
     
        public void addContain() {
            boxes[0].add(new JLabel("RECHERCHE D'UN CONTENEUR"));
            boxes[0].add(Box.createHorizontalStrut(10));
            boxes[0].add(fields[0]);
            boxes[0].add(Box.createHorizontalStrut(320));
            boxes[0].add(buttons[0]);
     
            boxes[1].add(Box.createHorizontalGlue());
            boxes[1].add(buttons[1]);
     
            boxes[2].add(scrolls[0]);
     
            if (!(from.equals("location")||from.equals("storing"))){
                boxes[3].add(buttons[2]);
                boxes[3].add(Box.createHorizontalStrut(10));
                boxes[3].add(buttons[3]);
                boxes[3].add(Box.createHorizontalStrut(10));
            }
            boxes[3].add(Box.createHorizontalStrut(10));
            boxes[3].add(buttons[4]);
            boxes[3].add(Box.createHorizontalStrut(50));
            boxes[3].add(buttons[5]);
            boxes[4].add(new JLabel("CODE CLIENT"));
            boxes[4].add(Box.createHorizontalStrut(10));
            boxes[4].add(fields[1]);
            boxes[4].add(Box.createHorizontalStrut(100));
            boxes[4].add(new JLabel("NOM DE LA SOCIETE"));
            boxes[4].add(Box.createHorizontalStrut(10));
            boxes[4].add(fields[2]);
            boxes[4].add(Box.createHorizontalStrut(100));
            boxes[5].add(boxes[0]);
            boxes[5].add(Box.createVerticalStrut(20));
            boxes[5].add(boxes[1]);
            boxes[5].add(Box.createVerticalStrut(20));
            boxes[5].add(boxes[2]);
            boxes[5].add(Box.createVerticalStrut(20));
            boxes[5].add(boxes[3]);
            boxes[5].add(Box.createVerticalStrut(20));
            boxes[5].add(boxes[4]);
     
            getMainPanel().add(boxes[5]);
        }
     
        public void initItems() {
            fields[1].setText(getJavarch().getCurrentCustomer().getIdentifiantCustomer());
            fields[2].setText(getJavarch().getCurrentCustomer().getNomSociete());
            if (from.equals("storing")) {
                buttons[4].setText("SELECTIONNER LE CONTENEUR");
            }
        }
     
        public Table createTable() throws SQLException {
            Table ret = new Table();
            String querry;
            if (from.equals("search")) {
                querry = "SELECT client, identifiantConteneur, emplacement, nombrePresent, etat FROM Conteneur WHERE client ='"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"' AND etat <> 'ABANDONNE';";
                ResultSet res = getJavarch().getDatabase().getResult(querry);
                allOfContainer = EngineMethods.getObjects(res,5);
                int[] collumns = {1,2,4};
                listForTable = EngineMethods.keepUsedOnly(allOfContainer, collumns);
            }
            else if (from.equals("location")) {
                querry = "SELECT DISTINCT identifiantConteneur, E.etat, E.nombrePresent, capacite, emplacement FROM Conteneur C , Emplacement E WHERE emplacement = identifiantEmplacement AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"' AND C.etat <> 'ABANDONNE';";
                System.out.println(querry);
                ResultSet res = getJavarch().getDatabase().getResult(querry);
                allOfContainer = EngineMethods.getObjects(res,5);
                int[] collumns = {0,2,4};
                listForTable = EngineMethods.keepUsedOnly(allOfContainer, collumns);
            }
            else if (from.equals("storing")) {
                querry = "SELECT client, identifiantConteneur, emplacement, nombrePresent, etat FROM Conteneur WHERE client ='"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"' AND etat <> 'COMPLET' AND etat <> 'ABANDONNE';";
                ResultSet res = getJavarch().getDatabase().getResult(querry);
                allOfContainer = EngineMethods.getObjects(res,5);
                int[] collumns = {1,2,3,4};
                querry = "SELECT identifiantConteneur, COUNT(*) FROM Conteneur WHERE client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"'";
            res = getJavarch().getDatabase().getResult(querry);
            res.next();
            int nbContainer = res.getInt(1);
            if (nbContainer==0) {
                JOptionPane.showMessageDialog(this, "Ce client n'a aucun conteneur à ce jour.", "Mise en emplacement", JOptionPane.INFORMATION_MESSAGE);
            }
            else {
                try {allOfContainer[0][0].toString();}
                catch(ArrayIndexOutOfBoundsException ex) {
                    int choice = JOptionPane.showConfirmDialog(this, "Tous les conteneurs de ce client sont complets.Pour définir un conteneur partiel :\n      - Cliquez sur le menu recherche\n      - Sélectionnez le conteneur réellement partiel\n      - Cliquez sur le boutton \"COMPLET >> PARTIEL\"\n\nDésirez-ouvrir cette fenêtre maintenant ?", "Mise en conteneur", JOptionPane.YES_NO_OPTION);
                    if (choice==JOptionPane.YES_OPTION) {
                        new SearchContainer (getJavarch(), "search");
                        yes=false;
                    }
                }
            }
                listForTable = EngineMethods.keepUsedOnly(allOfContainer, collumns);
            }
            tableModels[0] = new TableModel(listForTable, titles);
            ret.setModel(new TableModel(listForTable, titles));
            ret.setPreferredScrollableViewportSize(new Dimension (0,400));
            return ret;
        }
     
        public void displayPopup(MouseEvent me) {
            final int NBITEMS = 5;
            JPopupMenu popup = new JPopupMenu();
            JMenu menu = new JMenu("Sélectionner les colonnes");
            options  = EngineMethods.cuttingString(titles, 0);
            checkMenuList = new JCheckBoxMenuItem[options.length];
                for(int i=0; i<checkMenuList.length; i++) {
                checkMenuList[i] = new JCheckBoxMenuItem(options[i]);
                checkMenuList[i].addActionListener(this);
                checkMenuList[i].setSelected(isSelectedCollumns[i+1]);
                menu.add(checkMenuList[i]);
            }
            String [] listItemTitles = {"Copier la ligne", "Tout copier", "Exporter la table vers Excel", "Exporter la table vers Word", "Imprimer"};
            listItems = new JMenuItem[NBITEMS];
            popup.add(menu);
            for (int i=0; i<listItems.length; i++) {
                listItems[i] = new JMenuItem(listItemTitles[i]);
                listItems[i].addActionListener(this);
                popup.add(listItems[i]);
            }
            popup.show(tables[0], me.getX(), me.getY());
        }
     
        private void getSelection() throws ArrayIndexOutOfBoundsException {
            String[] attributes = new String[allOfContainer[0].length];
            for (int i=0; i<allOfContainer.length; i++) {
                if (allOfContainer[i][0] == tables[0].getValueAt(tables[0].getSelectedRow(), 0)) {
                    for (int j=0; j<allOfContainer[0].length; j++) {
                        attributes [j] = allOfContainer[i][j].toString();
                    }
                }
            }
            if (attributes[0].equals("")) throw new ArrayIndexOutOfBoundsException();//no container
            container = new javarch.components.Container(attributes);
            getJavarch().setCurrentContainer(container);
            this.dispose();
        }
     
        private void updateContain(String state) throws SQLException, ArrayIndexOutOfBoundsException{
            ArrayList<Integer> idContainer = EngineMethods.getSelectedRowNumber(listForTable, EngineMethods.getSelectedKeysTable(tables[0]));
            int selectedRow = tables[0].getSelectedRow();
            if (idContainer.size()<1) throw new ArrayIndexOutOfBoundsException();
            getJavarch().getDatabase().update("START TRANSACTION;");
            for (int i=0; i<idContainer.size(); i++) {
                String querry = "UPDATE Conteneur SET etat = '"+state+"' WHERE identifiantConteneur = '"+listForTable[idContainer.get(i)][0]+"' AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"';";
                getJavarch().getDatabase().update(querry);
                if (from.equals("search")) listForTable[idContainer.get(i)][2] = state;
                else if (from.equals("location")) listForTable[idContainer.get(i)][2] = state;
                else if (from.equals("storing")) listForTable[idContainer.get(i)][3] = state;
            }
            getJavarch().getDatabase().update("COMMIT;");
            tables[0].setModel(new TableModel(EngineMethods.setData(isSelectedCollumns, isSelectedRows, listForTable), EngineMethods.setTitle(isSelectedCollumns, titles)));
            tables[0].setRowSelectionInterval(selectedRow, selectedRow);
        }
     
        private void outLocation() throws SQLException, ArrayIndexOutOfBoundsException{
            int row = tables[0].getSelectedRow();
            ArrayList<Integer> idContainer = EngineMethods.getSelectedRowNumber(listForTable, EngineMethods.getSelectedKeysTable(tables[0]));
            if (idContainer.size()<1) throw new ArrayIndexOutOfBoundsException();
            if (from.equals("search")||(from.equals(""))) {
                getJavarch().getDatabase().update("START TRANSACTION;");
                for (int i=0; i<idContainer.size(); i++) {
                    String querry = "UPDATE Conteneur SET emplacement = NULL WHERE identifiantConteneur = '"+listForTable[idContainer.get(i)][0]+"' AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"';";
                    getJavarch().getDatabase().update(querry);
                    listForTable[idContainer.get(i)][1] = "";
                }
                getJavarch().getDatabase().update("COMMIT;");
            }
     
            else if(from.equals("location")) {
                getJavarch().getDatabase().update("START TRANSACTION;");
                for (int i=0; i<idContainer.size(); i++) {
                    String querry = "UPDATE Conteneur SET emplacement = NULL WHERE identifiantConteneur = '"+listForTable[idContainer.get(i)][0]+"' AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"';";
                    getJavarch().getDatabase().update(querry);
                }
                getJavarch().getDatabase().update("COMMIT;");
                for (int i=0; i<idContainer.size(); i++) {
                    isSelectedRows[idContainer.get(i)] = false;
                }
            }
            tables[0].setModel(new TableModel(EngineMethods.setData(isSelectedCollumns, isSelectedRows, listForTable), EngineMethods.setTitle(isSelectedCollumns, titles)));
            tables[0].setRowSelectionInterval(row, row);
     
        }
     
        private void deleteContainer() throws SQLException, ArrayIndexOutOfBoundsException {
            int row = tables[0].getSelectedRow();
            int choice = JOptionPane.showConfirmDialog(this, "Le fait de supprimer un conteneur va considérer l'ensemble des boîtes qu'il contient comme étant nouvelle.\nEtes-vous sûr de vouloir supprimer le conteneur ?", "Demande de confirmation", JOptionPane.YES_NO_OPTION);
            if (choice==JOptionPane.YES_OPTION) {
                ArrayList<Integer> idContainer = EngineMethods.getSelectedRowNumber(listForTable, EngineMethods.getSelectedKeysTable(tables[0]));
                if (idContainer.size()<1) throw new ArrayIndexOutOfBoundsException();
                getJavarch().getDatabase().update("START TRANSACTION;");
                for (int i=0; i<idContainer.size(); i++) {
                    String querry = "UPDATE Boite SET etat = 'NOUVELLE' WHERE conteneur = '"+listForTable[idContainer.get(i)][0]+"' AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"';";
                    getJavarch().getDatabase().update(querry);
                    querry = "UPDATE Conteneur SET etat = 'ABANDONNE', emplacement = NULL WHERE identifiantConteneur = '"+listForTable[idContainer.get(i)][0]+"' AND client = '"+getJavarch().getCurrentCustomer().getIdentifiantCustomer()+"';";
                    getJavarch().getDatabase().update(querry);
                    isSelectedRows[idContainer.get(i)] = false;//to don't display the selected row
                }
                getJavarch().getDatabase().update("COMMIT;");
                tables[0].setModel(new TableModel(EngineMethods.setData(isSelectedCollumns, isSelectedRows, listForTable), EngineMethods.setTitle(isSelectedCollumns, titles)));
                try {
                    tables[0].setRowSelectionInterval(row, row);
                }
                catch (IllegalArgumentException e) {
                    try {
                        tables[0].setRowSelectionInterval(row-1, row-1);
                    }
                     catch (IllegalArgumentException ex) {
                         JOptionPane.showMessageDialog(this, "Tous les conteneurs du client ont été supprimés. La liste est donc vide.\nLa fenêtre va se fermer", "Le client n'a plus de conteneur", JOptionPane.INFORMATION_MESSAGE);
                         this.dispose();
                     }
                }
     
            }
        }
        private String selectContainer() throws ArrayIndexOutOfBoundsException{
            String ret = "";
            String [] attributes = new String[allOfContainer[0].length];
            for (int i=0; i<listForTable.length; i++) {
                if (listForTable[i][0] == tables[0].getValueAt(tables[0].getSelectedRow(), 0)) {
                    if (from.equals("")){
                        for (int j=0; j<listForTable[0].length; j++) {
                            attributes [j] = listForTable[i][j].toString();
                        }
                        ret = listForTable[i][1].toString();
                    }
                    else if (from.equals("location")) {
                        System.out.println(i);
                        attributes [0] = allOfContainer[i][0].toString();
                        attributes [1] = getJavarch().getCurrentCustomer().getIdentifiantCustomer();
                        attributes [2] = listForTable[i][2].toString();
                        attributes [3] = listForTable[i][1].toString();
                        attributes [4] = listForTable[i][0].toString();
                    }
                    else if (from.equals("storing")) {
                        attributes [0] = listForTable[i][0].toString();//id
                        attributes [1] = getJavarch().getCurrentCustomer().getIdentifiantCustomer();//client
                        attributes [2] = listForTable[i][3].toString();//emplacement
                        attributes [3] = listForTable[i][2].toString();//nbpres
                        attributes [4] = listForTable[i][1].toString();//etat
                    }
                    else if (from.equals("search")) {
                        attributes [0] = allOfContainer[i][1].toString();//id
                        attributes [1] = getJavarch().getCurrentCustomer().getIdentifiantCustomer();//client
                        attributes [2] = allOfContainer[i][2].toString();//emplacement
                        attributes [3] = allOfContainer[i][3].toString();//nbpres
                        attributes [4] = allOfContainer[i][4].toString();//etat
                    }
                }
            }
            getJavarch().setCurrentContainer(new javarch.components.Container(attributes));
            return ret;
        }
     
        public void actionPerformed(ActionEvent e) {
            for (int i=0; i<buttons.length; i++) {
                if (e.getSource().equals(buttons[i])) {
                    switch (i) {
                        case (0) :
                            try {updateContain("PARTIEL");}
                            catch (SQLException ex) {JOptionPane.showMessageDialog(this, "Impossible de définir le conteneur comme étant partiel.\n"+ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);}
                            catch (ArrayIndexOutOfBoundsException ex) {
                                ex.printStackTrace();
                                JOptionPane.showMessageDialog(this, "Veuillez sélectionner un conteneur", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                        break;
                        case (1) :
                            try {updateContain("COMPLET");}
                            catch (SQLException ex) {JOptionPane.showMessageDialog(this, "impossible de définir le conteneur comme étant complet.\n"+ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);}
                            catch (ArrayIndexOutOfBoundsException ex) {
                                ex.printStackTrace();
                                JOptionPane.showMessageDialog(this, "Veuillez sélectionner un conteneur", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                        break;
                        case (2) :
                            try {deleteContainer();}
                            catch (SQLException ex) {JOptionPane.showMessageDialog(this, "Impossible de supprimer le conteneur dans la base de données.\n"+ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);}
                            catch (ArrayIndexOutOfBoundsException ex) {JOptionPane.showMessageDialog(this, "Veuillez sélectionner un conteneur", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                        break;
                        case (3) :
                            try {outLocation();}
                            catch (SQLException ex) {JOptionPane.showMessageDialog(this, "Impossible de sortir le conteneur de son emplacement.\n"+ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);}
                            catch (ArrayIndexOutOfBoundsException ex) {JOptionPane.showMessageDialog(this, "Veuillez sélectionner un conteneur", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                        break;
                        case (4) :
                            selectContainer();
                            if(from.equals("location")||from.equals("search")){
                                try {
                                   // getJavarch().setCurrentLocation(selectLocation());
                                    new ViewContainer(getJavarch(), "search");
                                    this.dispose();
                                }
                                catch (ArrayIndexOutOfBoundsException ex) {JOptionPane.showMessageDialog(this, "Veuillez sélectionner un emplacement", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                            }                    
                            else if (from.equals("storing")){
                                try {
                                    //String customer = selectContainer();
                                    new ContaineringBySelection(getJavarch());
                                    this.dispose();
                                }
                                catch (ArrayIndexOutOfBoundsException ex) {JOptionPane.showMessageDialog(this, "Veuillez sélectionner un conteneur", "Pas de sélection", JOptionPane.WARNING_MESSAGE);}
                            }
                        break;
                        case (5) :this.dispose();
                        break;
                    }
                }
            }
     
            try {
                for(int i=0; i<listItems.length; i++) {
                    if (e.getSource().equals(listItems[i])) {
                        switch(i) {
                            case(0):
                                String currentRow = EngineMethods.getSelectedRowString(tables[0].getSelectedRow(), listForTable);
                                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(currentRow), null);
                            break;
                            case(1):
                                String allRows = EngineMethods.getAllRowsString(tables[0].getRowCount(), listForTable);
                                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(allRows), null);
                            break;
                            case(2):
                                try {new XLSGenerator();}
                                catch (FileNotFoundException ex) {}
                                catch (IOException ex) {}
                            break;
                            case(3):
                                try {new DOCGenerator();}
                                catch (FileNotFoundException ex) {}
                                catch (IOException ex) {}
                            break;
                            case(4): EngineMethods.Print();
                            break;
     
                        }
                    }
                }
     
                for(int i=0; i<checkMenuList.length; i++) {
                    if(e.getSource().equals(checkMenuList[i])){
                        EngineMethods.setIsSelected(isSelectedCollumns, !isSelectedCollumns[i+1], i+1);
     
                        tables[0].setModel(new TableModel(EngineMethods.setDataByCollumn(isSelectedCollumns, listForTable), EngineMethods.setTitle(isSelectedCollumns, titles)));
                        tables[0].clearSelection();
                    }
                }
             }
            catch (NullPointerException ex) {}
        }
     
        public void insertUpdate(DocumentEvent e) {
            if (e.getDocument().equals(fields[0].getDocument())) {
                try {
                    sorter[0].setRowFilter(new RowFilter<TableModel,Integer>() {
                        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
                            return (EngineMethods.isSmaller((String)entry.getValue(0), EngineMethods.completeNumber(Integer.parseInt(fields[0].getText()), 6)));
                        }
                    });
                }
                catch (NumberFormatException ex){}
                if (fields[0].getText().equals("")) {
                    sorter[0].setRowFilter(new RowFilter<TableModel,Integer>() {
                        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
                            return (EngineMethods.isSmaller((String)entry.getValue(0), EngineMethods.completeNumber(Integer.parseInt("0"), 6)));
                        }
                    });
                }
            }
        }
     
        public void removeUpdate(DocumentEvent e) {
            insertUpdate(e);
        }
     
        public void changedUpdate(DocumentEvent e) {
        }
     
        public void focusGained(FocusEvent e) {
            try {
                getListSorter().add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
                getSorter()[0].setSortKeys(getListSorter());
                tables[0].setRowSorter(getSorter()[0]);
            }
            catch (IllegalArgumentException ex) {}
            catch (NullPointerException ex) {}
            catch (ArrayIndexOutOfBoundsException ex) {}
            getListSorter().clear();
        }
     
        public void focusLost(FocusEvent e) {
        }
     
        private String selectLocation() throws ArrayIndexOutOfBoundsException{
            String ret = "";
            String [] attributes = new String[listForTable[0].length+1];
            for (int i=0; i<listForTable.length; i++) {
                if (listForTable[i][0] == tables[0].getValueAt(tables[0].getSelectedRow(), 0)) {
                    if (from.equals("")){
                        for (int j=0; j<listForTable[0].length; j++) {
                            attributes [j] = listForTable[i][j].toString();
                        }
                        ret = listForTable[i][1].toString();
                        attributes [0] = listForTable[i][0].toString();
                        attributes [1] = listForTable[i][3].toString();
                        attributes [2] = getJavarch().getCurrentLocation().getIdentifiantEmplacement();
                        attributes [3] = listForTable[i][1].toString();
                        attributes [4] = listForTable[i][2].toString();
                        ret = listForTable[i][3].toString();
                    }
                }
            }
            getJavarch().setCurrentLocation(new javarch.components.Location(attributes));
            return ret;
        }
     
        public void keyTyped(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public void keyPressed(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public void keyReleased(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
    }
    Merci d'avance

  2. #2
    Membre émérite Avatar de Heimdal
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    549
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 549
    Par défaut
    Tu parles d'un défi.

    Tout est la:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    buttons = new Button[10];              
    buttons[0].setText("SELECTIONNER");
    A quoi t'attendais-tu en bossant avec un tableau non rempli?

  3. #3
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JDBC][STATEMENT] NullPointerException
    Par syvid dans le forum JDBC
    Réponses: 2
    Dernier message: 23/03/2005, 00h29
  2. [Débutant]NullPointerException
    Par Crazyblinkgirl dans le forum Langage
    Réponses: 4
    Dernier message: 18/08/2004, 13h58
  3. [Exception]Double buffering & NullPointerException
    Par Seiya dans le forum API standards et tierces
    Réponses: 25
    Dernier message: 09/07/2004, 18h41
  4. Heritage et NullPointerException
    Par Assiobal dans le forum Langage
    Réponses: 6
    Dernier message: 18/06/2004, 16h35
  5. JPanel & getGraphics() : NullPointerException
    Par dingoth dans le forum Composants
    Réponses: 7
    Dernier message: 21/05/2004, 15h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo