-1

my code permit to put list content in jtable by using the method "save1" which is used in a jbutton. The problem is that there are some exception after running. This line of instructions "DefaultTableModel tableModel = fen.getmodel();" in the method save1 is the reason of the exception.

Here is the codes of "save1", the button and the exceptions:

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)
  • I suggest you install IntelliJ/Eclipse/ and use the auto format function. This code is really hard to read... – Imus Apr 05 '17 at 11:25
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Imus Apr 05 '17 at 11:27

1 Answers1

0

You get a NullPointerException. This means that on the line

DefaultTableModel tableModel = fen.getmodel();

you are calling a method on something that is null.

Hint: the line above is commented out. So what exactly is the current value of ´fen`?

Imus
  • 802
  • 6
  • 11
  • "fen" is a reference to another class named Fenetre1 witch has contain the "jtable" – R.Boubakri Apr 05 '17 at 13:16
  • //The 2 slaches at the start of this sentence turn it into a comment. This means it does not get compiled in java. In the code as you posted it here the fen isn't a reference to anything. It's just an unknown variable that isn't initialised yet. Thus the NullPointerException. Try removing those 2 slaches and see if the problem persists. – Imus Apr 05 '17 at 14:29