[jdom-interest] Re: Getting attribute name/value pairs

Matthias Brauch mb at biss-net.com
Wed Jul 19 12:50:20 PDT 2000


On Wed, 19 Jul 2000 09:41:53 -0700 +0200, Frank Cohen wrote:

>I used CVS to get the latest code. Finding the same problem: I get
>a "java.lang.ClassCastException: org.jdom.Element" exception when
>I try to cast the >Attribute object. Below is the XML document, the
>source and the exception thrown. Any help would be most appreciated.
>Thanks, in advance. -Frank
>

The problem in your start method is located in the inner loop
( "while ( property_iterator.hasNext() )"): instead of
      Object q = property_iterator.next();
you wrote 
      Object q = iterator.next(); 
Since iterator is the outer loop's iterator, this results in two
problems:
1. q may hold different types (not only attributes); this
causes the ClassCastException (yes, you have some
if q instanceof xxx statements in this method, but there
is a cast to Attribute before these).
2. Since property_iterator.hasNext() is always true
(because there is no property_iterator.next()) you will
sooner or later get a NoSuchElementException from
iterator.next().

HTH
Matthias




--
=====================================================================
Matthias Brauch
BISS GmbH, Chaukenweg 12, D-26388 Wilhelmshaven, Germany
Phone: +49/4423/9289/0, Fax: +49/4423/9289/99
EMail: mb at biss-net.com
=====================================================================





More information about the jdom-interest mailing list