2017-04-05 3 views
-1

mein Code erlauben, Listeninhalt in jtable mit der Methode "save1", die in einem jbutton verwendet wird, zu setzen. Das Problem ist, dass es nach dem Ausführen einige Ausnahmen gibt. Diese Zeile der Anweisungen "DefaultTableModel tableModel = fen.getmodel();" in der Methode save1 ist der Grund der Ausnahme.Jtable Füllung sequentiell in Java

Hier ist die Codes von "SAVE1", die Taste und die Ausnahmen:

public void save1(String pathToExplore) throws IOException, JDOMException{ 
ArrayList<String>liste= getArrowTexts(); 

System.out.println(liste); 
Lister_path diskFileExplorer = new Lister_path(pathToExplore,true); 
ArrayList<String> result= diskFileExplorer.Lister_path(); 
Lister_Rep listerep=new Lister_Rep(pathToExplore,true); 
    ArrayList<String> result1= listerep.Lister_Rep(); 
      int l=0,row=0,i=0; 
    //Fenetre1 fen=new Fenetre1(); 
    DefaultTableModel tableModel = fen.getmodel(); 
    while(i< result.size()&& l<result1.size()){ 
    String nompath=result.get(i); 
    ReadExeLS reedexel=new ReadExeLS(); 
     ArrayList<String> lisn=reedexel.ReadEx(nompath); 
     int j=0,k=0;int S=0; 
     while(j<liste.size()&&k<lisn.size()){ 
      if((liste.get(j)).equals(lisn.get(k))){ 
       System.out.println(liste.get(j)); 
       j++;k++;S++; 

       System.out.println(S); 
       if(j==liste.size()){ 
        k=lisn.size();} 
       else{ k++;} 

      }else{k++; 
      System.out.println(S);} 

     } 
    if(S==0){ 



     System.out.println(result1.get(l)); 
     tableModel.addRow(new String[] {"Not case","Success","Failed"}); 
     tableModel.setValueAt(result1.get(l), row, 2); 
      l++;row++;i++; 




    }else if(S==liste.size()){ 
     System.out.println(result1.get(l)); 
     tableModel.addRow(new String[] {"Not case","Success","Failed"}); 
    tableModel.setValueAt(result1.get(l), row, 1); 
    l++;row++;i++;} 
    else{ 
    tableModel.addRow(new String[] {"Not case","Success","Failed"}); 
    tableModel.setValueAt(result1.get(l), row, 0); 
    System.out.println(result1.get(l)); 
    l++;row++;i++; 

    } 




    } 

} 





public void actionPerformed(ActionEvent e) { 



    String path="C:\\Users\\W.S.I\\Desktop\\Bureau\\76\\20161129\\IMSI-627010102119665"; 
     try { 
      save1(path); 
     } catch (IOException ex) { 
      Logger.getLogger(Exemple.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (JDOMException ex) { 
      Logger.getLogger(Exemple.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 


    }); 








    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 
at Exemple.Save1(Exemple.java:475) 
at Exemple$1.actionPerformed(Exemple.java:94) 
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) 
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:6533) 
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 
at java.awt.Component.processEvent(Component.java:6298) 
at java.awt.Container.processEvent(Container.java:2236) 
at java.awt.Component.dispatchEventImpl(Component.java:4889) 
at java.awt.Container.dispatchEventImpl(Container.java:2294) 
at java.awt.Component.dispatchEvent(Component.java:4711) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) 
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) 
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) 
at java.awt.Container.dispatchEventImpl(Container.java:2280) 
at java.awt.Window.dispatchEventImpl(Window.java:2746) 
at java.awt.Component.dispatchEvent(Component.java:4711) 
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) 
at java.awt.EventQueue.access$500(EventQueue.java:97) 
at java.awt.EventQueue$3.run(EventQueue.java:709) 
at java.awt.EventQueue$3.run(EventQueue.java:703) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) 
at java.awt.EventQueue$4.run(EventQueue.java:731) 
at java.awt.EventQueue$4.run(EventQueue.java:729) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 
+0

Ich empfehle, dass Sie IntelliJ/Eclipse/ installieren und die automatische Formatierungsfunktion verwenden. Dieser Code ist wirklich schwer zu lesen ... – Imus

+0

Mögliche Duplikate von [Was ist eine NullPointerException, und wie behebe ich es?] (Http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and -how-do-i-fix-it) – Imus

Antwort

0

Sie eine Nullpointer bekommen. Dies bedeutet, dass auf der Linie

DefaultTableModel tableModel = fen.getmodel(); 

Sie eine Methode auf etwas fordern, die null ist.

Hinweis: Die obige Zeile ist auskommentiert. Was genau ist der aktuelle Wert von "fen"?

+0

"fen" ist ein Verweis auf eine andere Klasse namens Fenetre1, die die "jtable" enthält –

+0

// Die 2 Slatches am Anfang dieses Satzes machen es zu einem Kommentar. Dies bedeutet, dass es nicht in Java kompiliert wird. In dem Code, wie Sie ihn hier gepostet haben, ist das Fen kein Verweis auf irgendetwas. Es ist nur eine unbekannte Variable, die noch nicht initialisiert ist. Also die NullPointerException. Versuchen Sie, diese 2 Löschungen zu entfernen und sehen Sie, ob das Problem weiterhin besteht. – Imus