Results 1 to 5 of 5
- 08-02-2011, 01:51 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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.gif)
thanks in advance
cheersLast edited by roybean; 08-02-2011 at 01:52 PM. Reason: using java not php
- 08-02-2011, 03:18 PM #2
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
db
- 08-02-2011, 04:19 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
How do i do a SSCCE :$
- 08-02-2011, 04:49 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
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
- 08-03-2011, 08:35 AM #5
Similar Threads
-
ArrayIndexOutOfBoundsException
By np2392 in forum New To JavaReplies: 3Last Post: 01-26-2011, 10:28 PM -
ArrayIndexOutOfBoundsException: 10 ??
By Yakg in forum New To JavaReplies: 2Last Post: 12-04-2010, 06:56 PM -
ArrayIndexOutOfBoundsException: 0
By mxsar in forum New To JavaReplies: 3Last Post: 11-16-2010, 10:59 PM -
ArrayIndexOutOfBoundsException
By er1c550n20 in forum New To JavaReplies: 2Last Post: 04-07-2010, 06:50 PM -
ArrayIndexOutOfBoundsException
By flaskvacuum in forum New To JavaReplies: 6Last Post: 07-14-2009, 05:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks