Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Novice Newsgroups: comp.lang.java.gui Subject: Strange JTable issue in Sun's Java code Date: Mon, 16 Jan 2012 18:34:43 +0000 (UTC) Organization: Your Company Lines: 130 Message-ID: NNTP-Posting-Host: GVOB0RK//wnRbilLE4mzUg.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: Xnews/5.04.25 X-Antivirus-Status: Clean X-Notice: Filtered by postfilter v. 0.8.2 X-Antivirus: avast! (VPS 120116-0, 2012-01-16), Outbound message Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4942 I'm getting an exception I don't understand when I attempt to delete all the data in a small Jtable (46 rows, 3 columns). Here's the stacktrace; the "rowCount = 45" is a diagnostic I'm writing: ======================================================================== rowCount = 45 Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 at javax.swing.SizeSequence.removeEntries(SizeSequence.java:383) at javax.swing.JTable.tableRowsDeleted(JTable.java:4500) at javax.swing.JTable.tableChanged(JTable.java:4399) at javax.swing.table.AbstractTableModel.fireTableChanged (AbstractTableModel.java:280) at javax.swing.table.AbstractTableModel.fireTableRowsDeleted (AbstractTableModel.java:245) at hang.PhraseListTableModel.deleteAllRows (PhraseListTableModel.java:634) at hang.PhraseListEditor.actionPerformed(PhraseListEditor.java:625) at javax.swing.AbstractButton.fireActionPerformed (AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed (DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:357) at javax.swing.plaf.basic.BasicMenuItemUI.doClick (BasicMenuItemUI.java:1223) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased (BasicMenuItemUI.java:1264) at java.awt.Component.processMouseEvent(Component.java:6263) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent (Container.java:4574) at java.awt.LightweightDispatcher.processMouseEvent (Container.java:4238) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) ======================================================================== The crash is happening in the Java code but here's my deleteAllRows() so that you can see nothing very exotic is happening: ======================================================================== public int deleteAllRows() { String METHOD_NAME = "deleteAllRows()"; //$NON-NLS-1$ if (DEBUG) this.logger.entering(this.CLASS_NAME, METHOD_NAME); int rowCount = getRowCount(); //FIXME: remove the next line System.err.println("rowCount = " + rowCount); //temporary this.phraseList.removeAllElements(); fireTableRowsDeleted(1, rowCount); return rowCount; } ======================================================================== When I debug the code and follow it into the Java code, some odd things are happening. First, the actual fireTableRowsDeleted() method shows a valid value for the "this" parameter but displays the following for each of the other parameters when I inspect them via the Eclipse debugger: "firstRow [or whatever] cannot be resolved to a variable". I don't recall ever seeing that before in debugging a program. Then, when I proceed beyond that to the removeEntries(int, int) method, things continue to be strange. When I get to line 383 of that method, I get the same "cannot be resolved to a variable" notation on EVERY variable in that line, even variable i, which has just been explicitly set to 0. Here's the complete code for this method: ======================================================================== /** * Removes a contiguous group of entries * from this SizeSequence. * Note that the values of start and * length must satisfy the following * conditions: (0 <= start < getSizes().length) * AND (length >= 0). If these conditions are * not met, the behavior is unspecified and an exception * may be thrown. * * @param start the index of the first entry to be removed * @param length the number of entries to be removed */ public void removeEntries(int start, int length) { int sizes[] = getSizes(); int end = start + length; int n = a.length - length; a = new int[n]; for (int i = 0; i < start; i++) { a[i] = sizes[i] ; } for (int i = start; i < n; i++) { a[i] = sizes[i+length] ; } setSizes(a); } ======================================================================== I've never encountered a situation like this before. It feels like the problem is in the Java code - or Eclipse - and I'm not sure what to do about that. Is this nature's way of telling me that I need a newer Java JDK? I'm using Java 1.6.18. If not, what should I be doing? -- Novice