[英]Using try-with-resources in Netbeans
I have a try-catch statement in a Java servlet class. 我在Java servlet类中有一个try-catch语句。 Netbeans shows an error on this:
Netbeans显示错误:
try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources)
-source 1.6不支持try-with-resources(使用-source 7或更高版本来启用try-with-resources)
How can I get rid of this error? 我怎样才能摆脱这个错误?
It looks like you found my thread from the NetBeans forums, in which I posted the solution: 看起来您从NetBeans论坛找到了我的帖子,我在其中发布了解决方案:
I got the error to go away.
我得到了错误消失。
Right click on project > Properties > Sources > Source/Binary Format: JDK 7 > OK.
右键单击项目>属性>源>源/二进制格式:JDK 7>确定。
Source: 资源:
Error: "try-with-resources is not supported in -source 6 (use -source 7 or higher to enable try-with-resources)": 错误:“-source 6中不支持try-with-resources(使用-source 7或更高版本以启用try-with-resources)”:
http://forums.netbeans.org/ntopic42154.html http://forums.netbeans.org/ntopic42154.html
Ok it didn't work for me. 好吧,它对我不起作用。 Because in "Source/Binary Format:" there isn't "JDK 7".
因为在“源/二进制格式:”中没有“JDK 7”。
My solution was: Right click on project > Properties > Libraries > Manage Plataforms > Add Plataform, and choose your "jdk1.7.0_45" directory click on NEXT put a name "JDK 1.7" and FINISH. 我的解决方案是:右键单击项目>属性>库>管理Plataforms>添加Plataform,然后选择您的“jdk1.7.0_45”目录,单击NEXT,将名称“JDK 1.7”和FINISH。
Now you can modify your source format: Right click on project > Properties > Sources > Source/Binary Format: JDK 7 > OK. 现在您可以修改源格式:右键单击项目>属性>源>源/二进制格式:JDK 7>确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.