我的代码允许使用方法" save1"将列表内容放入jtable中。用于jbutton。问题是运行后有一些异常。 这行说明" DefaultTableModel tableModel = fen.getmodel();"在方法save1中是异常的原因。
以下是" save1"的代码,按钮和例外:
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 :(得分:0)
你得到一个NullPointerException。 这意味着就行了
DefaultTableModel tableModel = fen.getmodel();
您正在调用null
的某个方法。
提示:上面的行被注释掉了。那么'fen`的当前值究竟是什么?