Results 1 to 3 of 3
  1. #1
    MGeorge's Avatar
    MGeorge is offline Aging Hacker
    Join Date
    Sep 2014
    Location
    East (San Francisco) Bay, California, USA
    Posts
    20
    Rep Power
    0

    Default J2SE DefaultListModel .remove() throws ArrayIndexOutOfBoundsException

    I'm writing sort of an electronic tub file using SQLite and a Swing UI (J2SE 1.8.0_91). I'm unable to delete rows from my JList after deleting the database entry. My JList setup includes the code

    Java Code:
            protected DefaultListModel dbListModel;
                                    *
                                    *
                                    *
            DbListListener dbl = new DbListListener();
            dbList.setModel(dbListModel);
    The code that attempts to delete a row from the list is

    Java Code:
           mainPanel.dbUpdate(curTrack);  / refreshes curTrack instance as per UI
           int row = mainPanel.dbList.getSelectedIndex();
           String msg = db.execureUpdate(curTrack.deleteCommand());
           if (msg.length() > 0) {
               mainPanel.setMessage(msg, Color.RED);  // SQlite reported failure
           }
           else {
               mainPanel.setMessage("");
               int size = mainPanel.dbListModel.size();
               System.out.format("delete %d of %d\n", row, size);
               mainPanel.dbListModel.remove(row);
               curTrack = (Track) mainPanel.dbList.getSelectedValue();
           }
    When calling dbListModel.remove(), the Vector within the DefaultListModel
    is throwing an ArrayIndexOutOfBoundsException. Note the output immediately
    preceding the stack trace shows that I'm trying to delete row 5 when the
    model contains 7 rows! I've written this sort of code before and had no failures.
    Any advice would be appreciated.

    Java Code:
    delete 5 of 7
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    	at java.util.Vector.elementData(Vector.java:734)
    	at java.util.Vector.elementAt(Vector.java:477)
    	at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:89)
    	at us.mgeorge.tunetool.MainPanel$DbListListener.valueChanged(MainPanel.java:750)
    	at javax.swing.JList.fireSelectionValueChanged(JList.java:1796)
    	at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1810)
    	at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
    	at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
    	at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
    	at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:677)
    	at javax.swing.plaf.basic.BasicListUI$Handler.intervalRemoved(BasicListUI.java:2601)
    	at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:179)
    	at javax.swing.DefaultListModel.remove(DefaultListModel.java:498)
    	at us.mgeorge.tunetool.Main$ActionHandler.dbActionPerformed(Main.java:228)
    	at us.mgeorge.tunetool.Main$ActionHandler.actionPerformed(Main.java:186)
    	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:758)
    	at java.awt.EventQueue.access$500(EventQueue.java:97)
    	at java.awt.EventQueue$3.run(EventQueue.java:709)
    	at java.awt.EventQueue$3.run(EventQueue.java:703)
    	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:731)
    	at java.awt.EventQueue$4.run(EventQueue.java:729)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    	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)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: J2SE DefaultListModel .remove() throws ArrayIndexOutOfBoundsException

    What's the code here:
    us.mgeorge.tunetool.MainPanel$DbListListener.value Changed(MainPanel.java:750)

    That's where I would debug to check it is doing what you want in reaction to a row being deleted from the table.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: J2SE DefaultListModel .remove() throws ArrayIndexOutOfBoundsException

    Thanks for the PM.
    Not sure why the Reply With Quote didn't work, but sometimes this site can be a bit flaky!
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. DefaultListModel Issue
    By ERUKSPATEL in forum Threads and Synchronization
    Replies: 1
    Last Post: 01-20-2011, 05:08 AM
  2. Printing DefaultListModel to .txt
    By Embercloud in forum New To Java
    Replies: 6
    Last Post: 01-14-2011, 04:26 AM
  3. Wierd delay in DefaultListModel.addElement()
    By DaedalusAlpha in forum AWT / Swing
    Replies: 4
    Last Post: 04-19-2010, 07:51 AM
  4. DefaultListModel Elements
    By jboy in forum New To Java
    Replies: 7
    Last Post: 10-24-2009, 03:23 AM
  5. Replies: 3
    Last Post: 04-24-2009, 06:28 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
  •