Results 1 to 11 of 11
- 09-19-2010, 09:57 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 7
- Rep Power
- 0
error "0 >= 0" when trying to delete a row
chau! please help me with row removing from JTable.
My code:
directoryModel extends DefaultTableModel and doesn't override "removeRow" method. When i try to delete a row, the error is:PHP Code:myButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { try { int selRow = table.getSelectedRow(); if (table.getRowCount() > 0) { directoryModel.removeRow(selRow); directoryModel.fireTableChanged(null); } } catch (Exception exp) { System.out.println(exp.getMessage()); } } });
"0 >= 0", "1 >= 0"...
i'm absolutely lost, cannot understand the error source. Please help.
-
Could you change this line:
to be instead:Java Code:System.out.println(exp.getMessage());
Then show us the entire error message.Java Code:exp.printStackTrace();
- 09-19-2010, 10:19 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 7
- Rep Power
- 0
uf, crazy message:
i guess you will understand it better than me:(PHP Code:java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 at java.util.Vector.removeElementAt(Vector.java:511) at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:446) at SystClasses.TreeEditTest$4.actionPerformed(TreeEditTest.java:192) 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.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) 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) BUILD SUCCESSFUL (total time: 8 seconds)
-
The error is telling your that you're trying to access an array that has no elements, and this line:
tells us that this is occurring on line 192 of the TreeEditTest.java code. So which line is that?Java Code:at SystClasses.TreeEditTest$4.actionPerformed(TreeEditTest.java:192)
My guess is it's the remove row line. Do you know for certain that the table model that is being acted on is the same one that is being displayed in the JTable?
You may wish to create and post an SSCCE (see here: SSCCE Link).Last edited by Fubarable; 09-19-2010 at 10:28 PM.
- 09-19-2010, 10:33 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 7
- Rep Power
- 0
thank you.
line 192 is:
when i run "table.getRowCount()", it displays 2 (). so my table is not empty. but why some array is empty, it's strange...PHP Code:myButton.addActionListener(new java.awt.event.ActionListener() {
- 09-19-2010, 10:36 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 7
- Rep Power
- 0
yes, i'm sure, because above i have "table = new JTable( directoryModel );"
- 09-19-2010, 10:44 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 7
- Rep Power
- 0
i think i understand my problem. you are right about the difference between table and tablemodel. i will try to solve it. thank you.
-
- 09-21-2010, 02:03 PM #9
Member
- Join Date
- Oct 2009
- Posts
- 13
- Rep Power
- 0
logically, 0 >= 0 doesn't make any sense , and the main error is the "ArrayOutOfBoundsException." Which means you are using an invalid array index. When you say 0>=0 its like your telling the program that 0>0 which is false. Maybe you meant to use a variable instead which would easily fix the problem? Example: x>=0
- 09-21-2010, 02:38 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
-
Similar Threads
-
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM -
How do we "Loop" through subfolders to delete files?
By Zrob in forum New To JavaReplies: 3Last Post: 09-26-2008, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks