intellij 想法 - 错误:java:源代码版本 1.9 无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46280859/
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
intellij idea - Error: java: invalid source release 1.9
提问by Alex
I'm trying to run my JSQL parser class, but I'm getting Error: java: invalid source release 1.9
.
我正在尝试运行我的 JSQL 解析器类,但我得到了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.
我试图遵循这个答案。我更改了文件>构建、执行、部署>Java编译器>项目字节码版本:1.8。但是,我无法将模块语言级别和项目语言级别更改为 1.8,因为没有选项。我仍然在下面遇到相同的错误。
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();
}
}
}
采纳答案by DeanM
Select the project, then File > ProjectStructure > ProjectSettings > Modules -> sources You probably have the Language Level set at 9:
选择项目,然后 File > ProjectStructure > ProjectSettings > Modules -> sources 您可能将 Language Level 设置为 9:
Just change it to 8 (or whatever you need) and you're set to go.
只需将其更改为 8(或您需要的任何值),您就可以开始了。
Also, check the same Language Level settings mentioned above, under Project Settings > Project
此外,在项目设置 > 项目下检查上述相同的语言级别设置
回答by Dmitry Kaltovich
I have had the same problem. There is an answer:
我曾经也有过一样的问题。有一个答案:
- 1.CTRL + ALT + SHIFT + S;
- Then go to "Modules";
- "Dependencies;
- Change "Module SDK".
- 1. CTRL + ALT + SHIFT + S;
- 然后转到“模块”;
- "依赖项;
- 更改“模块 SDK”。
Got it! Now u have Java 9!
知道了!现在你有了 Java 9!
回答by felvhage
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.
根据您的构建是如何设置的,这可能是要走的路。
回答by Tharkius
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.
对于尝试过 DeanM 的解决方案但无济于事的任何人来说,还有其他值得检查的问题,即您为项目配置的 JDK 版本。我想说的是,如果您已为您的项目配置了 JDK 8u191(例如),但将语言级别设置为高于 8 的任何级别,您将收到此错误。
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.
在这种情况下,最好询问项目负责人,哪个版本的 JDK 更适合编译源代码。
回答by amitsahu86
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:
我在 IntellijIdea 中也遇到了同样的问题,在选择项目后,文件 > 项目结构 > 项目设置 > 模块 - > 来源选项显示 - 语言级别设置为 9:
So, I Just change it to 8. Still my issue didn't got resolve.
所以,我只是将其更改为 8。我的问题仍然没有得到解决。
The main issue was with pom.xml. I reimported the pom.xml file and my issue got resolved.
主要问题是 pom.xml。我重新导入了 pom.xml 文件,我的问题得到了解决。
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.
因此,无论何时更改 pom.xml 文件,IDEA 都需要更新项目结构。例如,如果您添加了更多依赖项,IDEA 需要将它们添加为项目库。
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.
在“设置 > 构建、执行、部署 > 构建工具 > Maven > 导入”中,您可以选择“自动导入 Maven 项目”。当 pom.xml 更改时,这将自动调用“重新导入”操作。
回答by abitcode
When using maven project.
使用 Maven 项目时。
check pom.xml file
检查 pom.xml 文件
<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
如果您的机器上安装了 jdk 8,请将java.version
属性从更改9
为8
回答by Edward
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.
我刚刚遇到了类似的问题。该项目已使用 Java 9 打开,但即使在所有模块和项目都设置回 1.8 之后,我仍然收到错误消息。
I needed to force Gradle to refresh the project and then everything ran as expected.
我需要强制 Gradle 刷新项目,然后一切都按预期运行。
回答by Rogol
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
所以验证一下:文件 -> 设置 -> 构建、执行、部署 -> 编译器 -> Java 编译器 -> 项目字节码版本并将其值设置为 8
回答by likejudo
GradleI 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.
Gradle我遇到了同样的问题,更改早期解决方案中给出的所有设置没有任何区别。然后我去了 build.gradle 并找到了这一行并将其删除。
sourceCompatibility = '11'
and it worked! :)
它奏效了!:)