On Thu, 06 Oct 2005 14:06:52 +0100, Tinker <>
wrote:
> Hi,
>
> I have a question re. JDOM 1.0 (http://www.jdom.org) ... specifically
> relating to the getParent method used from the Element object.
>
> JDOM 1.0 release dated 9th September 2004
> (http://www.jdom.org/dist/binary/)
>
> The JavaDoc for JDOM 1.0 (http://www.jdom.org/docs/apidocs/index.html)
> indicates that the org.jdom.Element class is a subclass of
> org.jdom.Content
> and that the getParent method is inherited from org.jdom.Content.
>
> I checked the getParent method, which is indeed a method of
> org.jdom.Content.
>
> Any idea why calling...
>
> Element testParent = (Element)testElement.getParent();
>
> ... (where testElement is an Element object) might throw a
> java.lang.NoSuchMethodError exception(?)...
>
> Exception in thread "main" java.lang.NoSuchMethodError: org.jdom.Element:
> method getParent()Lorg/jdom/Element; not found
>
> Cheers,
> Paul
>
> Aside: please advise if there is a more appropriate group to post -
> thanks
>
>
I'm not sure it's entirely on-topic, but in fact the error is entirely
correct - according to the 1.0 API there is no method on Element with the
signature 'org.jdom.Element getParent()'. There is a 'org.jdom.Element
getParentElement()' method with that signature, but 'getParent' returns a
superinterface of Element, which doesn't count as far as this problem is
concerned.
What interests me is that this shouldn't have happened. getParent()
returns a 'Parent', an interface which 'Element' implements, so the cast
looks like it should have been fine, and even if not it shouldn't have
given this exception _at all_. Maybe I'm missing something in the rest of
the code, or in JDOM (I've only scanned the API myself), but it's odd, as
if that your call has been linked against the wrong method during
compilation. Is this compiled with javac?
I suppose it could be a version issue, with two versions of the JDOM jar
(or classes) on the classpath. Alternatively, if you're using
instrumentation or proxy classes, for example, the method signature may
have been changed at runtime.
A third alternative (though unlikely in this case I think) is that your
copy of the JDOM jar is corrupted, though I'd expect more colourful errors
than this nasty in that case.
Other than that, more information is needed. Where does testElement come
from? Is it made in your code, or does it originate inside JDOM? It the
method call you showed the actual invocation, or a paraphrase for
something else (e.g reflection)? Was it definitely NoSuchMethodError and
not NoSuchMethodException?
--
Ross Bamford ()