在我的代码中,我在使用以下代码关闭时删除所有行:
public void removeAllRows() {
System.out.println("Rowcount:\t" + this.getRowCount());
if ((this.getRowCount()-1) > 0) {
System.out.println("\nJetzt wird der Tabelleninhalt gelöscht\n");
for( int i = this.getRowCount()-1; i >= 0; i-- ) {
this.removeRow(i);
}
}
}
现在,当我想使用带有以下代码的刷新按钮更新内容时:
line = 0;
BufferedReader br = null;
String linesplit;
try {
System.out.println("*** Einchecken-Tabellen-Daten werden geladen ***");
br = new BufferedReader(new FileReader("tableData.txt"));
while ((linesplit = br.readLine()) != null) {
System.out.println(linesplit);
// String aufsplitten
String[] arr = linesplit.split(";");
for (int i = 0; i < arr.length; i++) {
if (i < (arr.length - 1)) {
getCheckinModel().setUpdateValueAt(arr[i], line, i);
} else {
getCheckinModel().setUpdateLastValueAt(arr[i], line, i);
}
}
line++;
System.out.println("\n Setted in line" + line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
我收到以下错误:
Exception in thread "AWT-EventQueue-0" 1;1;23.03.14;24.03.14l;Lukas;Müller;street;18;postcode;city;lukas@lukas.de;34567;Zimmer;Zimmer;Suite
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:474)
at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:664)
at de.richter.main.model.CheckinModel.setUpdateValueAt(CheckinModel.java:47)
at de.richter.main.interfaces.CheckinWindow$4.actionPerformed(CheckinWindow.java:460)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
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:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:724)
at java.awt.EventQueue$4.run(EventQueue.java:722)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
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)
如何使用以下方法删除后创建新行?