Results 1 to 5 of 5
  1. #1
    roybean is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default jComboBox1.removeAllItems(); returns a ArrayIndexOutOfBoundsException: -1

    Im using java netBeans.

    i had a jComboBox, that is filled with names and then get the data for these names.

    I need in some point of the program to remove all itens from jComboBox and refill with new data.

    But when i tried to use jComboBox1.removeAllItems();
    is return a ArrayIndexOutOfBoundsException: -1

    I tried several ways to solve the problem but the exception maintains:
    i put this after the initcomponents()
    this.jComboBox1.setModel(new DefaultComboBoxModel());

    even when i use the this.jComboBox1.setSelectedIndex(-1); to not had any item selected it gives an exception.


    For now to solve i remove all the itens manually and for the fist item i am only managed to remove after the new insertion when this item is the last.

    my scary solution:
    PHP Code:
    //remove
                for (int ii = (this.jComboBox1.getItemCount() - 1); ii > 0; ii--) {
    
                    System.out.println("indice" + ii);
                    //System.out.println(this.jComboBox1.getSelectedIndex());
                    System.out.println(this.jComboBox1.getItemAt(ii));
                    this.jComboBox1.removeItemAt(ii);
                }
    
    //new Fill
               for (int ii = 0; ii < playerList.size(); ii++) {
                    Players sdf = playerList.get(ii);
                    this.jComboBox1.insertItemAt(sdf.getPlayerName(), ii);
                }
    
    //remove ancient fist entrance
                jComboBox1.setSelectedIndex(0);
                this.jComboBox1.removeItemAt((this.jComboBox1.getItemCount() - 1));
                jComboBox1.setSelectedIndex(0);

    Please HELP
    thanks in advance
    cheers
    Last edited by roybean; 08-02-2011 at 02:52 PM. Reason: using java not php

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    db

  3. #3
    roybean is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    How do i do a SSCCE :$

  4. #4
    roybean is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Found and fix the problem when run the function removeAllItems()

    @ the same tme is was been performing the action performed for this combobox
    put a protection to not run when the list is empty!

    thanks for the help

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    Quote Originally Posted by roybean View Post
    How do i do a SSCCE :$
    Is it really so difficult to click the link and go through the page?

    db

Similar Threads

  1. ArrayIndexOutOfBoundsException
    By np2392 in forum New To Java
    Replies: 3
    Last Post: 01-26-2011, 11:28 PM
  2. ArrayIndexOutOfBoundsException: 10 ??
    By Yakg in forum New To Java
    Replies: 2
    Last Post: 12-04-2010, 07:56 PM
  3. ArrayIndexOutOfBoundsException: 0
    By mxsar in forum New To Java
    Replies: 3
    Last Post: 11-16-2010, 11:59 PM
  4. ArrayIndexOutOfBoundsException
    By er1c550n20 in forum New To Java
    Replies: 2
    Last Post: 04-07-2010, 07:50 PM
  5. ArrayIndexOutOfBoundsException
    By flaskvacuum in forum New To Java
    Replies: 6
    Last Post: 07-14-2009, 06:36 PM

Tags for this Thread

Posting Permissions

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