6
The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files

I recently installed Java 8. While executing an application, I got above mentioned error can you please help me.

I am using:

  1. Java - jdk1.8.0_51
  2. Tomcat - apache-tomcat-5.5.26
Sufian
  • 6,405
  • 16
  • 66
  • 120
Madhu
  • 99
  • 1
  • 1
  • 4
  • 3
    Can you post your code ? – Sid Aug 12 '15 at 04:55
  • "A class that you use needs an other class that is not on the classpath." - http://stackoverflow.com/questions/5547162/eclipse-error-indirectly-referenced-from-required-class-files – Ian2thedv Aug 12 '15 at 05:15

8 Answers8

4

Assuming you are using some IDE, like Eclipse. When you are using jdk 1.8 with IDE, you need to update your IDE to support version 1.8.

It does not matter you are using new jdk's feature or not, but compiler has to load new JRE files in order to compile your project.

kandarp
  • 4,979
  • 11
  • 34
  • 43
2

If you are using IntelliJ, go to:

File/Settings/Build, Execution, Deployment/Compiler/Java Compiler

and make sure "Use compiler" and "Project bytecode version" have the right configuration.

Esdras Lopez
  • 775
  • 12
  • 22
2

I had this same error and tried many things to fix it, but finally worked was remarkably simple: It turns that I was simply using an older version of Eclipse that did not support a "Compliance Level" setting of Java that was as high as my JRE. I merely upgraded to a newer version and the problem went away.

From what I understand about "Compliance Level", it's the version of Java that your program is supposed to work on. That much I found out from reading stuff on the net. But what the other solutions did not mention is that your IDE has to be able to be set to a level as high as your JRE. In my case, I was using JRE 1.8, but the highest compliance level my older IDE supported was 1.6.

IMO, this situation should have been flagged as an error by Eclipse. But as it was, I wasted two nights trying to figure this out.

EE_Sparky
  • 21
  • 1
1

Your project build path could be referring to a jre instead of JDK.

Go to your build path. (In eclipse right click and choose build path). Go to your libraries and replace the jre with the jdk.

jozzy
  • 2,863
  • 3
  • 15
  • 12
  • It important point that JKD is software development kit while JRE is a runtime env. Advice who had this problem see the different between JDK, JRE and JVM. https://www.guru99.com/difference-between-jdk-jre-jvm.html – Math-O5 Nov 16 '21 at 15:36
0

pom.xml version is 1.6? If this is the way,you would replace jdk1.8 with jdk1.6 ,and environment variable into jdk1.6。

0

Same strange problem occurred. It turned out that wrong jdk version was in JAVA_HOME

x__dos
  • 1,813
  • 3
  • 27
  • 47
0

There you are I had the same issue but moment I saw your question i got it fixed. problem is you are not using old version since there is mismatch of referencing with new version. this error will come.
Work around:
1. Change your java version to old.(In my case I had to change to 7)
2. Update each libray and jar file compatible to java 8 that way it will refer java not class file

Here is the image of environment variable in my problem
enter image description here

Kunchok Tashi
  • 2,413
  • 1
  • 22
  • 30
0

check if build path is set to run with JDK. It is important point that JKD is software development kit while JRE is a runtime env. Advice who had this problem see the different between JDK, JRE and JVM. https://www.guru99.com/difference-between-jdk-jre-jvm.html

Math-O5
  • 365
  • 3
  • 8