简体   繁体   English

此语言级别不支持 Intellij 功能 (...)。 我无法编译

[英]intellij feature (...) not supported at this language level. I can't compile

IntelliJ is showing me this error IntelliJ 向我展示了这个错误

I just built my new computer and none of my java stuff is working... My regular Intellij was working when I first tried it, but my android studio would't install because it couldn't find the path to the jdk.我刚刚建立了我的新电脑,我的 java 东西都没有工作......当我第一次尝试时,我的常规 Intellij 正在工作,但我的 android studio 无法安装,因为它找不到 jdk 的路径。 Here is the question that I asked about that. 是我问的问题。 Since that wasn't working, I had to reinstall java multiple times, and now my IntelliJ isn't working.由于那不起作用,我不得不多次重新安装 java,现在我的 IntelliJ 不起作用。 Here is a picture of the error (I am getting an error that is telling me the for-each loops aren't supported at this language level).这是错误的图片(我收到一个错误,告诉我在此语言级别不支持 for-each 循环)。

I have tried to install the JDK on my D: drive and that didn't work.我试图在我的 D: 驱动器上安装 JDK,但没有奏效。 I am currently trying to use java 1.8u71 (have tried u65 and 1.7u47) except none of those have worked.我目前正在尝试使用 java 1.8u71(已尝试过 u65 和 1.7u47),但这些都没有奏效。

IntelliJ is showing me this error IntelliJ 向我展示了这个错误

此语言级别不支持

Matching the SDK/JDK with Project language level将 SDK/JDK 与项目语言级别匹配

To activate Java language features in the editor, you need to change your module's Project Structure or Module Settings to ensure your Project SDK matches the Project language level .要在编辑器中激活 Java 语言功能,您需要更改模块的项目结构模块设置,以确保您的项目 SDK项目语言级别相匹配。

Project SDK (JDK) Java 1.5 matches project language level 5 ...项目 SDK (JDK) Java 1.5 匹配项目语言级别 5 ...

Java 1.6 matches language level 6 ... Java 1.6 匹配语言级别 6 ...

Java 1.7 matches language level 7, and so on. Java 1.7 匹配语言级别 7,依此类推。

Example例子

Depending on your IntelliJ version, hit F4 or Ctrl + Alt + Shift - S on your module in the Project pane, or hit Ctrl + Shift - A and type either "Project Structure" or "Module Settings" to open the Project Structure dialog.根据您的 IntelliJ 版本,在项目窗格中的模块上F4Ctrl + Alt + Shift - S ,或按 Ctrl + Shift - A并键入“项目结构”或“模块设置”以打开项目结构对话框。

Under Project Settings section, click on the first item in the list, Project .Project Settings部分下,单击列表中的第一项Project

In the screenshot below, the Project SDK 1.8 (java version '1.8.0_72') matches the selected language level SDK Default (8 - Lambdas, type annotations etc.) because Java 1.8 matches SDK level 8. This activates the Java 8 language features for use in the editor.在下面的屏幕截图中,项目 SDK 1.8 (java version '1.8.0_72')匹配所选语言级别的SDK Default (8 - Lambdas, type annotations etc.)因为 Java 1.8 匹配 SDK 级别 8。这会激活 Java 8 语言功能在编辑器中使用。

项目结构

If you don't have the JDK set up under Project SDK that is a different problem.如果您没有在Project SDK下设置 JDK,那就是另一个问题了。 Solve that one first by clicking New and adding a JDK.首先通过单击New并添加 JDK 来解决该问题。

When I had multiple independent modules in the project, I had to do below setting in addition to @activedecay's answer : Under Project Settings , click on Modules .当我在项目中有多个独立模块时,除了@activedecay 的回答之外,我还必须进行以下设置:在Project Settings ,单击Modules Select specific module.选择特定模块。 Select appropriate Language Level .选择适当的Language Level

截屏

I had this same problem and none of the solutions I have found worked.我遇到了同样的问题,但我发现的所有解决方案都没有奏效。

I was using Maven projects and so decided to try running a maven install .我正在使用 Maven 项目,因此决定尝试运行maven install It too said:它也说:

[ERROR]  thefile.java:[24,77] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] theFile.java:[91,62] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)

So I added the properties to the Maven build pom.xml file:所以我将属性添加到 Maven 构建pom.xml文件中:

<properties>
    <spring.version>4.1.6.RELEASE</spring.version>
    <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

And refreshed the Maven project in IntelliJ.并在 IntelliJ 中刷新了 Maven 项目。 It worked!有效!

I also had the same problem.我也有同样的问题。

While I was accessing a static method of an interface through the name of the interface, I got the error saying当我通过接口名称访问接口的静态方法时,我收到错误消息

static interface method invocations are not supported at this language level 5此语言级别 5 不支持静态接口方法调用

As this is Java 1.8, I have checked some things:由于这是 Java 1.8,我检查了一些内容:

  1. I am using Intellij.我正在使用 Intellij。 So by doing CTRL + ALT + SHIFT + S Project Structure dialog box opens, go to因此,通过执行CTRL + ALT + SHIFT + S项目结构对话框打开,转到

    Project -> Project language level项目 -> 项目语言级别

    set this to SDK default (8-Lambdas,type annotations etc).将此设置为 SDK 默认值(8-Lambdas、类型注释等)。

  2. In Project structure open在项目结构中打开

    Modules -> Sources -> Language level模块 -> 来源 -> 语言级别

    set this to Project default (8-Lambdas,type annotations etc).将此设置为项目默认值(8-Lambdas,类型注释等)。

  3. Apply-> OK.申请-> 确定。

Then the error will go away.然后错误就会消失。

Another issue I had that caused this error in a Gradle project was the sourceCompatibility setting in the build.gradle file.在 Gradle 项目中导致此错误的另一个问题是 build.gradle 文件中的sourceCompatibility设置。 This must also match the value you are expecting to need.这也必须与您期望需要的值相匹配。 The default value that I have seen IntelliJ use when creating a new Gradle project is 1.5 .我在创建新 Gradle 项目时看到 IntelliJ 使用的默认值是1.5 If you are using lambdas, for instance, this will cause the build to fail.例如,如果您使用 lambda,这将导致构建失败。

Let me tell the solution in one image.让我用一张图片告诉解决方案。

  • File -> Project Structure -> Modules -> Properties tab -> Source Compatibility (Java 8)文件 -> 项目结构 -> 模块 -> 属性选项卡 -> 源代码兼容性(Java 8)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM