919
votes

Using IntelliJ IDE can't compile any projects. Screenshots of settings below:

Used JDK:

http://gyazo.com/b6e32119af7b04090d890cad04db6373

Project SDK and Language level:

http://gyazo.com/55a5fc9f7f2bb721a04780ce9d74eeab

Language Level:

http://gyazo.com/143bffad63fd89cafc231298729df2fc

Anybody have any ideas?

23
That doesn't look like an error from "pure Intellij"; aren't you using an ant buildscript or something?fge

23 Answers

1990
votes
  1. File > Settings > Build, Execution, Deployment > Compiler > Java Compiler
  2. Change Target bytecode version to 1.8 of the module that you are working for.

If you are using Maven

Add the compiler plugin to pom.xml under the top-level project node:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

(Hoisted from the comments.)

Note: If you don't mind reimporting your project, then the only thing you really need to do is change the pom and reimport the project, then IntelliJ will pick up the correct settings and you don't have to manually change them.

208
votes

You need to go to Settings and set under the Java compiler the following: enter image description here

also check the Project Settings

117
votes

This looks like the kind of error that Maven generates when you don't have the compiler plugin configured correctly. Here's an example of a Java 8 compiler config.

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!-- ... -->

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

<!-- ... -->

</project>
85
votes

The quickest way I found:

  • press:CTRL + SHIFT + A (For Mac + SHIFT + A)
  • type: java compiler
  • press: ENTER

In the Settings window, set the Target bytecode to 1.8

(or 9 for java9)

32
votes

There are two ways to solve this problem:

  1. Set settings (File -> Settings -> Build, Execution, Deployment -> Java Compiler): enter image description here
  2. Add a build section to your pom.xml: enter image description here
19
votes

Many answers regarding Maven are right but you don't have to configure the plugin directly.

Like described on the wiki page of the Apache Maven Compiler Plugin you can just set the 2 properties used by the plugin.

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>
14
votes

I fixed this by going to Project Structure -> Modules, find the module in question, click on Dependencies tab, change Module SDK to Project SDK.

9
votes

I fixed it just by changing target compile version to 1.8. Its in:

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

6
votes

You need to go to the /.idea/compiler.xml and change target to required jdk level.

enter image description here

5
votes

In my case I fixed this issue by opening .iml file of project (it is located in project root folder and have name same as the name of project) and changing line <orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" /> to <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />

I had everything configured as in others answers here but by some reason Idea updated .iml file incorrectly.

4
votes

I fixed it by modify my POM file. Notice the last comment under the highest voted answer.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
        </configuration>
</plugin>

The source must matches the target.

4
votes

I just re-import maven button, then the error disappeared.

enter image description here

4
votes

In your Gradle app level file >> compileOptions add this two lines

android {
  compileOptions {
    ...
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    ...
   }
}
3
votes

If you are working with Android-studio 1.3, Follow the below steps -

Go to File - Project Structure

Under modules- app-Properties tab, choose Source Compatibility -1.8 and

Target Compatibility - 1.8.

And you are good to go.

1
votes

Under compiler.xml file you will find :

<bytecodeTargetLevel>
  <module name="your_project_name_main" target="1.8" />
  <module name="your_project_name_test" target="1.8" />
</bytecodeTargetLevel>

and you can change the target value from your old to the new for me i needed to change it from 1.5 to 1.8

1
votes

I've just spent a while struggling with the same problem. The only thing that worked for me was not using the built mvn (3.3.9) but pointing it to an external downloaded version (3.5.0). Finally the project opened and everything was good.

1
votes

Don't forget to set dependencies for your module: enter image description here

1
votes

This issue occurs if your module is configured with Annotation processor and other module is not.Set the same configuration for all the modules as it wold be cyclic dependency.

0
votes

For me, the problem was about Maven not able to find proper configurations, since these items were specified in parent pom.

Changing File -> Settings -> Build, Excecution, Deployment -> Maven -> User Settings file to point to my custom settings with proper repositories fixed the problem that was otherwise hiding.

Found out about the problem through Help -> Show log in explorer -> clicking the log file, when previously only got the error in the title and "java.lang.NullPointerException" in the console.

0
votes

Solution of the problem is very simple.You have to open .idea/compiler.xml file on your İdea Project and

You should write appropriate target version

0
votes

With Intellij, using Maven, you must check that Intellij has auto-imported your project. You can check by clicking on the Maven tab on the right of your Editor.

enter image description here

If your Project is not here, then add the pom.xml file by clicking on +.

Obviously, the project must also have the relevant <build/> :

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
0
votes

If none of the other answers work, check your Module SDK.

I had this error pop up for me after I had updated the project SDK to 1.8, the Javac compiler to 1.8, etc. The setting that was the problem for me was the "Module SDK".

(on Linux) Go to File > Project Structure... then in the window that opens, select Modules under Project Settings. Select the module in question from the list and then the Dependencies tab and make sure that Module SDK is set appropriately.

0
votes

I have checked all of the above but the error still occurs.

But reimport all maven Projects (reload button inside Maven Projects panel) works in my case.