intellij feature (…) not supported at this languag

2019-01-23 14:23发布

IntelliJ is showing me this error

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. 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. 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).

I have tried to install the JDK on my D: drive and that didn't work. I am currently trying to use java 1.8u71 (have tried u65 and 1.7u47) except none of those have worked.

5条回答
Fickle 薄情
2楼-- · 2019-01-23 14:42

Another issue I had that caused this error in a Gradle project was the sourceCompatibility setting in the build.gradle file. 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. If you are using lambdas, for instance, this will cause the build to fail.

查看更多
祖国的老花朵
3楼-- · 2019-01-23 14:49

IntelliJ is showing me this error

are not supported at this language level

Matching the SDK/JDK with Project language level

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.

Project SDK (JDK) Java 1.5 matches project language level 5 ...

Java 1.6 matches language level 6 ...

Java 1.7 matches language level 7, and so on.

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.

Under Project Settings section, click on the first item in the list, 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.

project structure

If you don't have the JDK set up under Project SDK that is a different problem. Solve that one first by clicking New and adding a JDK.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-23 14:52

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

As this is Java 1.8, I have checked some things:

  1. I am using Intellij. So by doing CTRL+ALT+SHIFT+S Project Structure dialog box opens, go to

    Project -> Project language level

    set this to SDK default (8-Lambdas,type annotations etc).

  2. In Project structure open

    Modules -> Sources -> Language level

    set this to Project default (8-Lambdas,type annotations etc).

  3. Apply-> OK.

Then the error will go away.

查看更多
虎瘦雄心在
5楼-- · 2019-01-23 15:00

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. 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:

<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. It worked!

查看更多
别忘想泡老子
6楼-- · 2019-01-23 15:01

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. Select specific module. Select appropriate Language Level.

Screenshot

查看更多
登录 后发表回答