java.lang.NoSuchMethodError: org.jdom.Element: method getParent()Lorg/jdom/Element

T

Tinker

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
 
H

Harry Bosch

Hmm. Are you sure that this javadoc is correct? Perhaps the method
was moved down the chain and the javadoc is out of date.

Perhaps you are importing the wrong type of element?

Could you do a getClass().getName() and see what it is?
 
H

Harry Bosch

FYI, I just looked at the JDOM source and it that method does exist in
the Content superclass. So, it should be there. My guess is that your
importing the wrong class for Element. I have a feeling you are
importing an org.w3c.dom.Element.
 
R

Ross Bamford

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?
 
H

Harry Bosch

I am curious to know if there has been a resolution to the problem.
Has there been?
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top