简体   繁体   English

尝试使用此语言级别不支持的资源

[英]Try With Resources Not Supported at This Language Level

I'm using IntelliJ IDEA Ultimate 2016.2.1, have set Project SDK to my 1.8 version, Project Language Level to 8, Module SDK to my 1.8 version, and JDK home path to /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home. 我正在使用IntelliJ IDEA Ultimate 2016.2.1,将Project SDK设置为我的1.8版本,将Project Language Level设置为8,将模块SDK设置为我的1.8版本,将JDK主路径设置为/Library/Java/JavaVirtualMachines/jdk1.8.0_91。 JDK /内容/首页。

I have restarted the IDE. 我重新启动了IDE。

Still, I am getting ugly warnings about try-with-resources not supported at this language level. 尽管如此,我对这种语言级别不支持的资源尝试提出了丑陋的警告。 I have not used less than language level 8 in IntelliJ so this can't be due to something not refreshing. 我没有在IntelliJ中使用低于语言级别8,所以这不能归因于没有刷新的东西。 I am using a gradle build configuration - cleaned built and tried to run - says I'm running 1.5 but I can't figure out where 1.5 is mentioned. 我正在使用gradle构建配置 - 清理构建并尝试运行 - 说我正在运行1.5但我无法弄清楚提到1.5的位置。 In build.gradle i'm using: 在build.gradle我正在使用:

 apply plugin: 'java'
 apply plugin: 'application'
 sourceCompatibility = 1.8

Should I file an IntelliJ bug or am I still missing something? 我应该提交IntelliJ错误还是我还缺少某些东西?

EDIT: 编辑:

Running gradle in termianl outside of IntelliJ's system runs it fine. 在IntelliJ系统之外的termianl中运行gradle运行良好。 So the problem is IntelliJ related. 所以问题是IntelliJ相关。

I have found that IntelliJ sometimes defaults modules to language levels that don't match the set project SDK. 我发现IntelliJ有时会将模块默认为与设置项目SDK不匹配的语言级别。 Try right clicking on the module in the project explorer and select module settings and then the language level tab. 尝试右键单击项目资源管理器中的模块,然后选择模块设置,然后选择语言级别选项卡。 If that is set to Java 5 then update it to Java 8. 如果将其设置为Java 5,则将其更新为Java 8。

Hey @Calicoder just try to make change your Java compiler version into 1.7 or 1.8 as mentioned below 嘿@Calicoder只是尝试将您的Java编译器版本更改为1.7或1.8,如下所述

在此输入图像描述

Thanks hope this will help. 谢谢希望这会有所帮助。

Make sure your try-with-resources is using the correct semantics. 确保您的try-with-resources正在使用正确的语义。 For instance, this: 例如,这个:

try (new BufferedReader(request.getReader())) {

}

will produce that same error message. 将产生相同的错误消息。

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

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