0

In my code I delete all rows when closing with the following code:

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);
        }
    }
}

So now when I want to update the content with a refresh button with the following code:

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();
}

I receive the following error:

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)

How can I create new rows after deleting them with the following method?

icebat
  • 4,696
  • 4
  • 22
  • 36
  • Ist das dein Problem: http://www.java-forum.org/java-basics-anfaenger-themen/65804-java-lang-arrayindexoutofboundsexception-0-0-a.html ? – Binkan Salaryman May 06 '15 at 12:48
  • Vielleicht hilft dir mein Code-Schnipsel weiter: http://pastebin.com/FCfmWAcY (Paste wird in einem Tag automatisch gelöscht) – Binkan Salaryman May 06 '15 at 13:05
  • Das Löschen klappt einwandfrei. Habe dein Eindruck, dass eine Zeilenanzahl deklariert werden muss, bevor ich die neuen daten einfügen kann. Denke, dass ich das addRow ausführen muss, danke für den tipp! –  May 06 '15 at 14:47

0 Answers0