The method getTextContent() is undefined for the type Node

| May 3, 2012 | 16 Comments

eclipse

The method getTextContent() is undefined for the type Node
You can get this kind of error when your develop a system that use xml manipulation using library xml-apis. If you try to find a solution by a search in google you can find solutions like:

org.w3c.dom.Node.getTextContent() is only available as of Java 1.5

But, you are running and compile your project using Java 1.5. If yo
u are using Eclipse as IDE you can check this by right clicking on the project, Properties -> Java Compiler, and confirm that 1.5 or above are in the drop down lists. You also can see the projects facets to be sure.

Spotting the problem The method getTextContent() is undefined for the type Node in Eclipse

In the Eclipse “Problems” tab where you saw the  error (one time for each coincidence in the workspace).  If you don’t see that tab, go to Window -> Show View -> Problems.

The line with the problem may had the next apparence:

 

1
2
3
Node node = .....
 
.... node.getTextContext()...

 

Mouse over the capitalized word “Node” on the previous line, the yellow balloon assist should show “org.w3c.dom.Node”.

Now highlight the word Node. Right click, select Declarations -> Workspace.

In a moment a new “Search” tab should appear and report 2 declarations for org.w3c.dom.Node, in:

  • classes.jar in jdk libs.
  • xml-apis-1.0.b2.jar

It’s the second entry that’s causing the problem, it’s being pulled in from the contrib/extraction area, which Eclipse included but ant doesn’t.

The root cause of The method getTextContent() is undefined for the type Node

There are many jars packaged in the jdk libs and they sometimes contain the same library routines that xml-apis, but at different versions.  When Eclipse created the  project it tries to create a reasonable default classpath to build with, but the order matters, and in this case the list and order is different than what the ant build utility would have created.

The solution

The order of the classpath needs to be tweaked in Eclipse project; shove the xml-apis-1.0.b2.jar all the way to the bottom, past the built in JVM libraries. Probably if you use maven to deploy or package projects or ant you don´t have this problem.

¿How can i fix it in Eclipse?

Right click project, select Properties -> Java Build Path. The problem would stay with xml-apis-1.0.b2.jar and others related libraries such as xerces.

Go to Order and Export Tab, select the jdk library and click on buttom top to move it all the way up, so that have to be the first libraries to use.And it should not have a checkmark.

Save the settings with the OK button and Eclipse should recompile everything, it might take it a second to wake up.  But the Problems tab should now have no Errors, although still a ton of warnings.  But those are a matter for another day!

——————————————————————————————-

References:
http://www.enterprisesearchblog.com/2009/09/fix-for-gettextcontent-is-undefined-for-the-type-node-for-solr-project-in-eclipse-ide.html

Tags: ,

Category: Development, Java

Comments (16)

Trackback URL | Comments RSS Feed

  1. indra says:

    Thanks , Buddy . Your solution was as smooth as butter :)

  2. Armand says:

    Thx.
    I believe this problem happens now and then once Java is updated! I had it a couple of times and I fixed it without knowing what I was doing. Now I know :)

  3. Thanks a lot!

    It works!

    E.

  4. Kimo says:

    Thanks a lot Man !
    Very well expained and correctly solved my problem

  5. Revathi says:

    Thanks a lot,Its very useful…

  6. Jai says:

    Hi Paco,
    Thank you very much.
    It helped me to compile my office app in minutes. :) :)

  7. Sinisa says:

    Thank you very much, Paco! It solved my problems! :)

  8. AlexP says:

    Thank you!!!

  9. Arun Chaudhary says:

    Thanx a lot. It worked great.

  10. Prashanth says:

    Thankyou very much good information. It resolved my problem in a minute

  11. Mani Rai says:

    Thanks man. I was having this problem though I was using maven. I shoved down the maven dependecies behind JRE System Library. That fixed my problem.

Leave a Reply