Actually, when deleting many rows from the table, this exception pops up. And it happens that does not jump out. I am new and do not yet understand how to handle these exceptions. Complete exception log and add delete code:

for (int i=0; i<table.getSelectedRows().length;i++){ for (int u=0; u<list.size(); u++){ if (table.getSelectedRows()[i] == list.get(u).getRowNum()){ list.remove(u); u--; } } } table.setModel(model.table(list)); Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2 at java.util.Vector.elementAt(Unknown Source) at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source) at javax.swing.plaf.ComponentUI.update(Unknown Source) at javax.swing.JComponent.paintComponent(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintToOffscreen(Unknown Source) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source) at javax.swing.RepaintManager$PaintManager.paint(Unknown Source) at javax.swing.RepaintManager.paint(Unknown Source) at javax.swing.JComponent._paintImmediately(Unknown Source) at javax.swing.JComponent.paintImmediately(Unknown Source) at javax.swing.RepaintManager$4.run(Unknown Source) at javax.swing.RepaintManager$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.access$1200(Unknown Source) at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) 
  • I suppose that you run in a cycle from beginning to end, removing from the middle ... the index shifts ... and the pointer flies abroad as a result ........... but without a detailed description of what you are doing what, and when, and without bringing the code - it's hard to say anything - Alexey Shimansky
  • Most likely, delete the columns not in the EDT. - zRrr
  • 2
    it is not necessary to handle such an exception, it is necessary to correct the error that causes it. - rfq
  • I added a piece of code where I delete the selected rows of the table from the array and then re-shove the new array into the table model. What is EDT? In an Internet polazil and did not find anything sensible. And I forgot to write that all the necessary rows from the table are deleted and then this exception flies - user200303
  • How this code is called, and what table.setModel(model.table(list)); does table.setModel(model.table(list)); ? - zRrr

1 answer 1

  for (int u=0; u<list.size(); u++){ if (table.getSelectedRows()[i] == list.get(u).getRowNum()){ list.remove(u); u--; // так делать не надо и все будет хорошо } 

let's say list.size () = 10, and when the condition is met u decreases by 1 and eventually the loop

  for (int u=0; u<list.size(); u++) 

does not work 10 times but 11 or more and refers to a value that does not exist

  • Yes, u-- it was superfluous, it also removes, but the error did not disappear- ( - user200303
  • Then put the brakepoint and turn on the debag menu in the ide, well, step by step, see what and how you change - alexandr gaiduchok