Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error in Node.getTextContent for jdk 6

Tags:

java

java Source code not compiling with jdk 6.

 import org.w3c.dom.Node;
 Node node = list.item(0);
 String txtContent = node.getTextContent();

getTextContent() not found in the jdk 6

how can solve this compilation issue.

like image 789
Kamran Omar Avatar asked Apr 04 '11 05:04

Kamran Omar


2 Answers

I came here with the same problem. Even worse: I had two projects side by side, both targetting the same JRE (1.6), and one was able to resolve Node.getTextContent() while the other wasn't. I resolved it sort of by accident; I went to project properties | Java Build Path | Order and Export tab, selected the JRE (which was at the bottom of the list) and clicked the "Top" button to move it to the top. My problem went away. It appears that the Node I wanted was hidden by another one. :-\ Maybe this will help with your problem.

like image 110
Bryan Avatar answered Feb 24 '23 10:02

Bryan


Although a late post... maybe someone will find this useful.

I didn't like the manual project setting with JRE on top because all my colleagues would have to go trough this every time the project was imported, so I found another solution.

In my case I had the following dependency tree: org.reflections (0.9.8) -> dom4j (1.6.1) -> xml-apis (1.0.b2).

In order to fix it, I added an exclusion in the org.reflections dependency, like this:

<dependency>
    <groupId>org.reflections</groupId>
    <artifactId>reflections</artifactId>
    <version>0.9.8</version>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

In your case maybe there is another dependency that imports a faulty jar. E.g.: Dealing with "Xerces hell" in Java/Maven?

Please check http://www.jarfinder.com/index.php/java/info/org.w3c.dom.Node to see all the jars that contain that class.

like image 25
virussu_ro Avatar answered Feb 24 '23 10:02

virussu_ro