intellij idea - Error: java: invalid source release 1.9

JavaIntellij IdeaCompiler Errors

Java Problem Overview


I'm trying to run my JSQL parser class, but I'm getting Error: java: invalid source release 1.9.

I tried to following this answer. I changed File> Build,Execution,Deployment> Java Compiler> Project bytecode version: 1.8. However, I can't change the Module language level and Project language level to 1.8 because there's not option for that. I still get the same error below.

Error enter image description here

Code

package cs4321.project2;

import java.io.FileReader;
import net.sf.jsqlparser.parser.CCJSqlParser;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.Select;

public class Parser {
    private static final String queriesFile = "resources/input/queries.sql";

    public static void main(String[] args) {
        try {
            CCJSqlParser parser = new CCJSqlParser(new FileReader(queriesFile));
            Statement statement;
            while ((statement = parser.Statement()) != null) {
                System.out.println("Read statement: " + statement);
                Select select = (Select) statement;
                System.out.println("Select body is " + select.getSelectBody());
            }
        } catch (Exception e) {
            System.err.println("Exception occurred during parsing");
            e.printStackTrace();
        }
    }
}

Java Solutions


Solution 1 - Java

Select the project, then File > ProjectStructure > ProjectSettings > Modules -> sources You probably have the Language Level set at 9:

screenshot

Just change it to 8 (or whatever you need) and you're set to go.

Also, check the same Language Level settings mentioned above, under Project Settings > Project

enter image description here

Solution 2 - Java

Sometimes the problem occurs because of the incorrect version of the project bytecode.

So verify it : File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version and set its value to 8

Example

Solution 3 - Java

I have had the same problem. There is an answer:

  • 1.CTRL + ALT + SHIFT + S;
  1. Then go to "Modules";
  2. "Dependencies;
  3. Change "Module SDK".

Got it! Now u have Java 9!

Solution 4 - Java

intellij-invalid-source

You should to set the JAVA SDK and appropriate language level in the project settings. Click to enlarge.

Solution 5 - Java

> Maven Projects - and Project Structure[imported as maven in IntelliJ]

Try - If any of below pom entries present - values should be same at java level

<java.version>16</java.version>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
  1. Project Structure -> Project language level
  2. Module -> Language level


> GRADLE projects

Since we started working with GRADLE,

Build.gradle: - even below line didn't help

sourceCompatibility = '16'

I am getting this ERROR most of the time and Solution is Change Gradle JVM to XX

Preferences | Build, Execution, Deployment | Build Tools | Gradle -> JVM enter image description here

Solution 6 - Java

When using maven project.

check pom.xml file

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>9</java.version>
</properties>

if you have jdk 8 installed in your machine, change java.version property from 9 to 8

Solution 7 - Java

I was having this issue while running a SpringBoot project (Maven)

In my POM file I changed the java version from 11 to 8 and it worked:

<properties>
	<java.version>8</java.version> //The default was 11
</properties>

Make sure to Load maven changes else the change won't reflect.

Solution 8 - Java

I've just had a similar issue. The project had opened using Java 9 but even after all the modules and project were set back to 1.8, I was still getting the error.

I needed to force Gradle to refresh the project and then everything ran as expected.

Solution 9 - Java

Gradle I had the same issue and changing all the settings given in the earlier solutions made no difference. Than I went to the build.gradle and found this line and deleted it.

sourceCompatibility = '11'

and it worked! :)

Solution 10 - Java

Alternatively via Project Settings:

  • Project Settings
  • Project
  • Project language Level (set to fit your needs)

Depending on how your build is set up, this may be the way to go.

Solution 11 - Java

For anyone struggling with this issue who tried DeanM's solution but to no avail, there's something else worth checking, which is the version of the JDK you have configured for your project. What I'm trying to say is that if you have configured JDK 8u191 (for example) for your project, but have the language level set to anything higher than 8, you're gonna get this error.

In this case, it's probably better to ask whoever's in charge of the project, which version of the JDK would be preferable to compile the sources.

Solution 12 - Java

In Project Structure in Project SDK: modify SDK to 11 or higher and in Project language level: modify to 11 - Local variable syntax for lambda parameters

Solution 13 - Java

I also had the same problem in IntellijIdea, after selecting the project, then File > ProjectStructure > ProjectSettings > Modules -> sources the option was showing - the Language Level set at 9:

So, I Just change it to 8. Still my issue didn't got resolve.

The main issue was with pom.xml. I reimported the pom.xml file and my issue got resolved.

So, whenever you changed the pom.xml file, IDEA needs to update the project structure. For example if you've added there some more dependencies, IDEA needs to add them as project libraries.

In "Settings > Build, Execution, Deployment > Build Tools > Maven > Importing" you can choose "Import Maven projects automatically". This will automatically invoke "Reimport" action when the pom.xml is changed.

enter image description here

Solution 14 - Java

Just additional note:

when you creating a new project from start.spring.io make sure you select your JDK version theirs by default is set to JDK 11, later it will cause the above issue.

Solution 15 - Java

>>> File > Project Structure > Project > Project SDK > Choose Version >>> File > Project Structure > Project > Project Language Level > Choose Version >>> File > Project Structure > Modules > Sources Tab > Language Level > Choose Level >>> File > Project Structure > Modules > Dependencies Tab > Module SDK > Choose Version

>>> In Pom.xml under properties change to your version

<properties>
	<java.version>16</java.version>
</properties>

>>> Right Click Pom then Mavem then Reload Project

Solution 16 - Java

I was able to overcome this issue only clearing/removing the VM configuration. But you should do all the following checks:

  1. Menu File/Project Structure/Project (select the SDK and the correct language level -- in may case 1.8.0_201 and "8 - Lambdas...")

  2. Menu File/Project Structure/Modules/Sources (on the right) - Select the same Language Level

  3. Menu File/Project Structure/Dependencies (also on the right) - Select the same Module SDK

  4. (If still does not work...) Menu Run/Edit configurations

enter image description here

I removed the lines from the configuration and all start running.

--module-path
${PATH_TO_FX}
--add-modules
javafx.controls,javafx.fxml

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - JavaDeanMView Answer on Stackoverflow
Solution 2 - JavaRogolView Answer on Stackoverflow
Solution 3 - JavaDmitry KaltovichView Answer on Stackoverflow
Solution 4 - JavaGayan WeerakuttiView Answer on Stackoverflow
Solution 5 - JavaRavi ParekhView Answer on Stackoverflow
Solution 6 - JavaabitcodeView Answer on Stackoverflow
Solution 7 - JavaOjonugwa Jude OchalifuView Answer on Stackoverflow
Solution 8 - JavaEdwardView Answer on Stackoverflow
Solution 9 - JavalikejudoView Answer on Stackoverflow
Solution 10 - JavafelvhageView Answer on Stackoverflow
Solution 11 - JavaTharkiusView Answer on Stackoverflow
Solution 12 - JavaLucian L.View Answer on Stackoverflow
Solution 13 - Javaamitsahu86View Answer on Stackoverflow
Solution 14 - JavashubhamView Answer on Stackoverflow
Solution 15 - JavaEmmanuel NjorodongoView Answer on Stackoverflow
Solution 16 - JavaSamadView Answer on Stackoverflow