简体   繁体   English

IntelliJ错误 - 在-source 1.6错误中不支持java:try-with-resources。即使在项目设置中,也选择了1.7 JDK

[英]IntelliJ error - java: try-with-resources is not supported in -source 1.6 error. Even though in project settings 1.7 JDK is selected

Under File -> Project Structure -> SDKs i have 1.7 jdk but i still get this error: 在文件 - >项目结构 - > SDKs我有1.7 jdk但我仍然收到此错误:

added.java: try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources) added.java:-source 1.6不支持try-with-resources(使用-source 7或更高版本启用try-with-resources)

I have restarted IDE but to no avail 我已重新启动IDE但无济于事

Newer JVMs allow you to compile your code using compiler versions of lower JVM versions. 较新的JVM允许您使用较低JVM版本的编译器版本来编译代码。 For example, JDK 1.7 will allow you to compile your code using the 1.5 compiler. 例如,JDK 1.7允许您使用1.5编译器编译代码。

See the "Cross compilation section" here http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html 请参阅http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html中的“交叉编译部分”。

What you need to do in Intellij, is to go to File -> Project Structure -> Project and select the "Project SDK" as 1.7 and the "Project Language Level" as 7.0 您需要在Intellij中执行的操作是转到文件 - > 项目结构 - > 项目并选择“项目SDK”作为1.7,将“项目语言级别”作为7.0

不得不点击'错误​​灯泡'图标(或Alt + Enter)并选择选项以启用加载多捕获,尝试使用资源,钻石......然后重新加载并重新启动IDE。

IntelliJ IDEA allows to set the language level on a project basis as well as on on module basis. IntelliJ IDEA允许在项目基础上以及在模块基础上设置语言级别。 If you have set the language level to Java 7 or higher on the project level, and are still getting this error message, right click on the module, select "Open module settings". 如果您在项目级别将语言级别设置为Java 7或更高版本,并且仍然收到此错误消息,请右键单击该模块,选择“打开模块设置”。 Make sure the language level for the module is set to "Project default", or if for one reason, you want to set it specifically, it should be at least Java 7. 确保模块的语言级别设置为“Project default”,或者如果出于某种原因,您希望专门设置它,则它应至少为Java 7。

I had the same problem with IntelliJ 13. You have to set the language level, either for the entire project or individual modules, on the "General Settings for Project" dialog. 我在IntelliJ 13中遇到了同样的问题。您必须在“项目的常规设置”对话框中为整个项目或单个模块设置语言级别。 See IntelliJ IDE gives error when using Try-Catch with Resources for the complete answer. 有关完整答案,请参阅使用Try-Catch with Resources时IntelliJ IDE给出错误

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

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