Compilation error in Node.getTextContent for jdk 6 - 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.

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.

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.

I have also faced the similar problem. It is nothing to do with the Source Code. Steps to solve the problem is,
Go to project Properties (Right click on project and choose properties)
Select Java Build Path
Go to Order and Export tab
Make sure your JRE library is on TOP. If it is not in top, make it to top.
Click on OK and see after completing the build progress in right down.

For anyone working with hibernate the solution is similar to virussu_ro above.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>

Possibly a long shot, but are you sure you're using JDK 6? Sometimes IDEs like Eclipse have a dropdown in the Project window that lets you choose a version, and it may be set to 1.4. Or you may have your CLASSPATH set incorrectly. Worth checking if you have ever had Java 1.4 installed.
I ask because Node.getTextContent was added in JDK 1.5, so the only way I can explain its absence is that you are using the Java 1.4 version of org.w3c.dom.Node.

Try running this code to determine location of jar:
System.out.println(System.getProperty("java.version"));
ProtectionDomain domain = org.w3c.dom.Node.class.getProtectionDomain();
System.out.println("domain: " + domain);
CodeSource codeSource = domain.getCodeSource();
if(codeSource != null) {
System.out.println("location: " + codeSource.getLocation());
} else {
System.out.println("null location, probably JRE class");
}
Maybe there is a jar on classpath that contains org.w3c.dom.Node class and hides the correct one.

Related

Source not found- YahooFinance.class

I'm trying to implement code from https://github.com/sstrickx/yahoofinance-api on Eclipse in Java. When I run the program, I'm getting a several lines of errors that are being printed on the console. When I click on the errors, it takes me to a window named "YahooFinance.class" on Eclipse that says "Source not found." It asks me to change the attached source. I have added the source to C:/Program Files/Java/jdk-11.0.11/lib/src.zip on my computer, but I'm still getting the same error. Any help would be greatly appreciated!
[Screenshot of error][1]
[1]: https://i.stack.imgur.com/GZuL7.png
Edit:
This is the code that I am trying to compile from source:
Stock stock = YahooFinance.get("INTC");
BigDecimal price = stock.getQuote().getPrice();
BigDecimal change = stock.getQuote().getChangeInPercent();
BigDecimal peg = stock.getStats().getPeg();
BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();
stock.print();
My project is Maven-based and I have added this dependency to the pom.xml file:
<dependency>
<groupId>com.yahoofinance-api</groupId>
<artifactId>YahooFinanceAPI</artifactId>
<version>3.15.0</version>
</dependency>
After refreshing my project's Maven dependencies, like Kevin Hooke said to do, I am no longer getting the "Source not found" error. Thank all of you for your quick responses and help!
The source project you're trying to use is a Maven based project and provides instructions on how to include it as a dependency.
Create a new Maven project in Eclipse (or update your project to be Maven based, adding a pom.xml file, standard folder structures etc)
Edit your pom.xml file and add a dependency to the yahoofinance-api project:
<dependency>
<groupId>com.yahoofinance-api</groupId>
<artifactId>YahooFinanceAPI</artifactId>
<version>x.y.z</version>
</dependency>
Replace x.y.z with the version that you need to use
Refresh your project's Maven dependencies: right-click project, Maven -> Update Project

Immutables Criteria Syntax Error In JDK 11 Module

I have a project that I'm trying to play around with the Immutables Criteria: https://immutables.github.io/criteria.html
I added the following to my pom.xml:
<dependency>
<groupId>org.immutables</groupId>
<artifactId>criteria-inmemory</artifactId>
<version>2.8.2</version>
</dependency>
Everything seemed fine. However, I am having some issues getting things imported and working. I have no issues with Immutables.Value that works fine. When I import Criteria Eclipse complains about:
The type org.immutables.criteria.Criteria is not accessible
So I tried adding the module to my module-info.java as follows:
requires org.immutables.criteria-common;
Also tried:
requires org.immutables.criteria-inmemory;
I'm using Eclipse suggestions to auto-complete the module name because I don't really know what the module name should be but, when I add the above Eclipse says there is a syntax error with the "-" in the requires statement. So at this point I am kinda stuck! If anyone has any suggestions I would love to hear them!
Thanks!!
I was able to track down the issue with the Immutables Library and I posted the following issue: https://github.com/immutables/immutables/issues/1223
Basically, the library was creating an invalid Automatic-Module-Name tag in there pom.xml's when building the jar files. The values that we being set contained a "-" which is invalid.
Shoutout to #Naman for pointing me in the right direction! Thanks!
I am still wondering if it is possible to override the jar files module-name. It seems like it could be useful for users of a library to somehow override a libraries jar files module-name for situations like this.

Why IntelliJ IDEA doesn't see HttpClients?

I've added following into dependencies section of my pom.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
<scope>test</scope>
</dependency>
But when I add the 1st line of "Quick start guide" (http://hc.apache.org/httpcomponents-client-4.4.x/quickstart.html):
CloseableHttpClient httpclient = HttpClients.createDefault();
IntelliJ IDEA highlights "HttpClients" and tells me:
Cannot resolve symbol 'HttpClients'
It looks like I have mistake with configuration. What exactly is wrong? please advise how to add support for HttpClients into the project?
Thanks!
P.S. Learned a bit more, looks like "" is redundant and wrong for this case, I removed it but that didn't help: still non-compilable.
EDIT: If I put cursor to 'HttpClients' and hit "Alt-enter" the pop-up doesn't contain any class to import. See screenshot:
It looks like my IntelliJ had issues with caching, cleaning cache with following re-importing of the project helped.
I found tips on that here: IntelliJ inspection gives "Cannot resolve symbol" but still compiles code
P.S. Though few other project were broken as a result of this action. Looks like I need to keep learning :)
Download the jar file from
https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient/4.5.6/source-code
Extract the .jar file name httpclient-4.5.6.jar. Form a directry name lib under your project and import this .jar file to it. Right click your .jar file and click addtolibrary.

Cannot run Mallet TopicModel

I am trying to run Mallet`s topic modelling but got the following error:
Couldn't open cc.mallet.util.MalletLogger resources/logging.properties file.
Perhaps the 'resources' directories weren't copied into the 'class' directory.
Continuing.
Exception in thread "main" java.lang.IllegalArgumentException: Trouble reading file stoplists\en.txt at cc.mallet.pipe.TokenSequenceRemoveStopwords.fileToStringArray(TokenSequenceRemoveStopwords.java:144) at cc.mallet.pipe.TokenSequenceRemoveStopwords.<init>(TokenSequenceRemoveStopwords.java:73) at LDA.TopicModel.main(TopicModel.java:23)
I have already added all the jar files! Could you please advise what is the problem here?
Thanks,
I received the first error, which it's able to continue from, as well.
But the actual exception that stops you seems to be that you don't have the MALLET stop words list in the right place. I downloaded their en.txt stopwords list to a specific location and gave it a direct path instead of "stoplists/en.txt", which worked.
Your english stop words file is missing (stoplists\en.txt). Either try downloading the jar files again, or just use maven which will make it easier for you to import in your java project. In the Maven POM file add:
<dependencies>
<dependency>
<groupId>cc.mallet</groupId>
<artifactId>mallet</artifactId>
<version>2.0.8</version>
</dependency>
....
</dependencies>
Latest version can be found here.

BouncyCastle openssl cannot be resolved

I wanted to code from this answer but i have error The import org.bouncycastle.openssl cannot be resolved The import org.bouncycastle.openssl cannot be resolved and i have no idea how coudl i repair this becouse other bouncycastle libs are detected correctly.
I will be grateful for any ideas whats wrong. Im using eclipse and i have instaled bouncycastle like in this instruction itcsoultions
In addition to the provider (a.k.a. bcprov) and lightweight API, you also need the PKIX API, which provides the openssl package.
Either download bcpkix-jdk15on-150.jar from BC downloads page (direct link) and drop it in the same directory of bcprov or add it to your maven dependencies with its coordinates:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.50</version>
</dependency>
Whenever we get error saying "The import *** cannot be resolved", it means that there is problem with library. Here, bcprov-jdk jar is missing.
I did the following, and it worked for me!
1. Download bcprov-jdk15on-152.jar from https://www.bouncycastle.org/latest_releases.html
2. Right click on Project-->Properties-->Java Build Path-->Libraries tab--> Click on Add External JARs.. Select the path where you have the dowlnloaded bcprov-jdk15on-152.jar. Then click OK. That's it.

Categories