Issue with build path
Asked Answered
S

2

5

I'm trying to use the setTextContent method in the piece of code below and I'm getting this compilation error in Eclipse:

The method setTextContent(String) is undefined for the type Element

But once I changed the order of buildpath, I was able to compile this code without errors.

import org.w3c.dom.Element;
import org.w3c.dom.Node;

Element element = (Element) list.item(i);
Node node = list.item(i);
if ("Date ".equals(node.getNodeName())) {
    element.setTextContent("");
}

Is there any alternate way rather than changing the build path?

Somnus answered 3/12, 2013 at 15:50 Comment(1)
Definitely seems like a build path/class path problem. Whatever Element class that is in your classpath does not have a setTextContent(String) method.Dockage
I
19

getTextContent/setTextContent method were introduced with DOM Level 3 - which was added in Java 5. Which version of jre are you using and also check that you don't have two jre's installed.

You need to go to Properties for the project in eclipse. Then select "Java Build Path" and tab "Order and Export". Here you can arrange the order of dependencies. Ensure that your JRE is higher up then Maven Dependencies.

Go to Order and Export Tab, select the jdk library and click on Buton TOP to move it all the way up, so that have to be the first libraries to use.

Move the xml-apis-1.0.b2.jar (or the version you have) all the way to the bottom, past the built in JVM libraries.

Interrelated answered 3/12, 2013 at 15:57 Comment(1)
Resolved !! My JRE was at bottom than maven dependency. I just moved JRE up above maven dependency and error gone !!Afrikaans
C
1

Don't include two libraries with the same method signature on the same class.

In other words, if you duplicate fully-qualified classes, you are at the mercy of the classloader. When you can control it, fine, but personally, I think it's scary.

One even less-preferable solution would be to physically remove the offending functionality from one of the libraries, but then you may run into even worse problems.

Cent answered 3/12, 2013 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.