[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: Resetting Items In JComboBox?



I figured out the problem. My JComboBox listener was generating an
NullPointerException because I failed do a proper check. Here is a little
extra info about how to capture scrolling exception. I got it from another
mailing list. Thanks for everyone help.
Take It Easy,
D. Michael Nelson

1) What JDK version are you using? There was a problem with
removeAllItems() throwing a null pointer exception in 1.0[something]
(search the bug database for "+removallitems +exception"
2) I've come across several instances where removeAllItems would through a
NullPointerException in jdk 1.2 & 1.3 when the item count was 0. Try
checking the count and call removeAllItems only if it's greater than 0.
3) Put the following line somewhere at the beginning of your code:
System.err = System.out
Then when you run the program redirect the output to a file with
c:\> java ... > output.txt
(you can also redirect System.err to a file in your program with
System.setErr(new PrintStream(new FileOutputStream("output.txt")));

Cheers
Dmitry




-----Original Message-----
Hello,

I am having a problem with JComboBox. I am attempting to reset the item list
during excution of the program by using removeAllItems() method followed by
addItem() method.  However, the addItem() method bombs with an exception (I
cannot tell what type of exception was generated because it scrolls off the
WIN98 DOS console).  After, the exception is generated my JComboBox
ActionListener stops working?

It seemed to be straight forward to reset the JComboBox with the above
methods, obviously, I am doing something wrong. I have included a code
snippet to help illustrate what I am attempting to achieve.  Any
suggestions?  Thanks in advance.

Take It Easy,
D. Michael Nelson


JComboBox m_AnnotationCB

private void setAnnotationCB(Address address)
{
 m_AnnotationCB.removeAllItems();
 m_AnnotationCB.addItem((Object)"New");---->generates an exception?

 Vector annotationVectors =
m_annotationSB.getAnnotationsForAddress(address.getAddressID());

 if (annotationVectors.size() > 0)
 {
  Iterator annotationIterator = annotationVectors.iterator();
  m_rgAnnotations = new AddressService.Annotation[annotationVectors.size()];
  int iIndex = 0;
  while (annotationIterator.hasNext())
  {
    m_rgAnnotations[iIndex++1] =
(AddressService.Annotation)annotationIterator.next();
    System.out.println(m_rgAnnotations[iIndex-1].getAnnotation());

m_AnnotationCB.addItem(m_dateFormat.format(m_rgAnnotations[iIndex].getLastUp
datedDate()));
    The above line does not work?
  }
 }
}