Results 1 to 11 of 11
  1. #1
    Chika is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default error "0 >= 0" when trying to delete a row

    chau! please help me with row removing from JTable.

    My code:

    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());
                            }
                        }
            });
    directoryModel extends DefaultTableModel and doesn't override "removeRow" method. When i try to delete a row, the error is:

    "0 >= 0", "1 >= 0"...

    i'm absolutely lost, cannot understand the error source. Please help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Could you change this line:
    Java Code:
    System.out.println(exp.getMessage());
    to be instead:
    Java Code:
    exp.printStackTrace();
    Then show us the entire error message.

  3. #3
    Chika is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    uf, crazy message:

    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)
    i guess you will understand it better than me:(

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The error is telling your that you're trying to access an array that has no elements, and this line:

    Java Code:
     at SystClasses.TreeEditTest$4.actionPerformed(TreeEditTest.java:192)
    tells us that this is occurring on line 192 of the TreeEditTest.java code. So which line is that?

    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.

  5. #5
    Chika is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    thank you.

    line 192 is:

    PHP Code:
    myButton.addActionListener(new java.awt.event.ActionListener() {
    when i run "table.getRowCount()", it displays 2 (). so my table is not empty. but why some array is empty, it's strange...

  6. #6
    Chika is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    yes, i'm sure, because above i have "table = new JTable( directoryModel );"

  7. #7
    Chika is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    i think i understand my problem. you are right about the difference between table and tablemodel. i will try to solve it. thank you.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Chika View Post
    thank you.

    line 192 is:

    PHP Code:
    myButton.addActionListener(new java.awt.event.ActionListener() {
    when i run "table.getRowCount()", it displays 2 (). so my table is not empty. but why some array is empty, it's strange...
    This is not the correct line that is causing your error. If you're still having an error, re-look at your stackTrace (what I had you print out before), and then recheck the line. I can guarantee you that it's not this one.

  9. #9
    Jnoobs is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    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

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Jnoobs View Post
    logically, 0 >= 0 doesn't make any sense
    Mathematically and logically it does make sense but the expression 'X >= N' reads as follows 'your index X is equal or larger than the size N of the array' so an AIOOB exception is thrown.

    kind regards,

    Jos

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Jnoobs View Post
    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
    Logically the error statement makes complete sense as 0 is in fact >= 0. If you have an empty Vector and try to remove the element at position 0 (which doesn't exist), this type of error can occur.

Similar Threads

  1. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  2. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. Replies: 3
    Last Post: 09-26-2008, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •