无法解析 java.util.Comparator 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31956269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:49:31  来源:igfitidea点击:

The type java.util.Comparator cannot be resolved

java

提问by Madhu

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.

我最近安装了 Java 8。在执行应用程序时,我遇到了上面提到的错误,你能帮我吗?

I am using:

我在用:

  1. Java - jdk1.8.0_51
  2. Tomcat - apache-tomcat-5.5.26
  1. Java - jdk1.8.0_51
  2. Tomcat - apache-tomcat-5.5.26

回答by jozzy

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

您的项目构建路径可能指的是 jre 而不是 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.

转到您的构建路径。(在 Eclipse 中右键单击并选择构建路径)。转到您的库并将 jre 替换为 jdk。

回答by kandarp

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.

假设您正在使用一些 IDE,例如 Eclipse。当您在 IDE 中使用 jdk 1.8 时,您需要更新您的 IDE 以支持 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.

您是否使用新的 jdk 功能并不重要,但编译器必须加载新的 JRE 文件才能编译您的项目。

回答by JiangLongLiu

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。

pom.xml 版本是 1.6?如果是这种方式,您将 jdk1.8 替换为 jdk1.6 ,并将环境变量替换为 jdk1.6。

回答by kilonet

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

同样奇怪的问题发生了。原来错误的jdk版本在JAVA_HOME

回答by Esdras Lopez

If you are using IntelliJ, go to:

如果您使用的是 IntelliJ,请转到:

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

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

并确保“使用编译器”和“项目字节码版本”具有正确的配置。

回答by EE_Sparky

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.

我遇到了同样的错误并尝试了很多方法来修复它,但最终工作非常简单:结果是我只是使用旧版本的 Eclipse,它不支持与我的一样高的 Java 的“合规级别”设置JRE。我只是升级到更新的版本,问题就消失了。

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.

根据我对“合规级别”的理解,它是您的程序应该使用的 Java 版本。这是我从网上阅读的东西中发现的。但是其他解决方案没有提到的是,您的 IDE 必须能够设置为与您的 JRE 一样高的级别。就我而言,我使用的是 JRE 1.8,但我的旧 IDE 支持的最高合规性级别是 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.

IMO,这种情况应该被 Eclipse 标记为错误。但事实上,我浪费了两个晚上试图弄清楚这一点。

回答by kontashi35

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

你在那里,我遇到了同样的问题,但是当我看到你的问题时,我已经解决了。问题是您没有使用旧版本,因为与新版本的引用不匹配。这个错误会来。
解决方法:
1. 将您的 java 版本更改为旧版本。(在我的情况下,我必须更改为 7)
2. 更新每个与 java 8 兼容的库和 jar 文件,这样它将引用 java 而不是类文件

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

这是我的问题中环境变量的图像
在此处输入图片说明