jcombobox - arrayindexoutofbounds exception

S

Sue

I have the following code,
and always get the error exception
java.lang.ArrayIndexOutOfBoundsException

try{
jComboBox1.removeAllItems();
}
catch (Exception ex){
System.out.println("exception " + ex);
}

The value for selectedIndex for this combo box seems to default to -1
even though I change it to zero -- could this be the problem?

Thank you very much.
 
P

Paul van Rossem

I have the following code,
and always get the error exception
java.lang.ArrayIndexOutOfBoundsException

try{
jComboBox1.removeAllItems();
}
catch (Exception ex){
System.out.println("exception " + ex);
}

The value for selectedIndex for this combo box seems to default to -1
even though I change it to zero -- could this be the problem?

Thank you very much.
1) Are you sure your jComboBox1 contains any objects?
The selectedIndex == -1 indicates that nothing is selected; if the
combobox is empty you can't change the index to zero by selecting an object.

2) Are you sure the exception is raised by calling removeAllItems()?
It shouldn't do this, so I suspect you left out some essential code in
the above quote...

Paul.
 
S

sanjay manohar

-1 means no selection, 0 means the first item is selected. You should
not select item 0 after removing all items.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top