Issue with build path

4.1k views Asked by At

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?

2

There are 2 answers

1
Rahul Gupta On BEST ANSWER

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.

0
Dave Newton On

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.