IntelliJ 错误 - java: try-with-resources 在 -source 1.6 错误中不受支持。即使在项目设置中选择了 1.7 JDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17100806/
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 error - java: try-with-resources is not supported in -source 1.6 error. Even though in project settings 1.7 JDK is selected
提问by TastyCode
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 但无济于事
回答by Nerrve
Newer JVMs allow you to compile your code using compiler versions of lower JVM versions. For example, JDK 1.7 will allow you to compile your code using the 1.5 compiler.
较新的 JVM 允许您使用较低 JVM 版本的编译器版本来编译代码。例如,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-> Projectand select the "Project SDK" as 1.7 and the "Project Language Level" as 7.0
您需要在 Intellij 中执行的操作是转到File-> Project Structure->Project并选择“Project SDK”为 1.7,将“Project Language Level”选择为 7.0
回答by TastyCode
Had to click on the 'error bulb' icon (or Alt+Enter) and select option to enable load multi-catch, try with resources, diamond ... and then reload and restart IDE.
必须单击“错误灯泡”图标(或 Alt+Enter)并选择选项以启用加载多捕获、尝试使用资源、菱形...然后重新加载并重新启动 IDE。
回答by ocroquette
IntelliJ IDEA allows to set the language level on a project basis as well as on on module basis. 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". 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.
IntelliJ IDEA 允许基于项目和模块设置语言级别。如果您在项目级别将语言级别设置为 Java 7 或更高版本,但仍然收到此错误消息,请右键单击模块,选择“打开模块设置”。确保模块的语言级别设置为“项目默认”,或者如果出于某种原因,您想专门设置它,它至少应该是 Java 7。
回答by Nick A. Watts
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. See IntelliJ IDE gives error when using Try-Catch with Resourcesfor the complete answer.
我在 IntelliJ 13 中遇到了同样的问题。您必须在“项目的常规设置”对话框中为整个项目或单个模块设置语言级别。有关完整答案,请参阅IntelliJ IDE 在使用 Try-Catch 和资源时出错。