【场景】调用com.sun.awt.AWTUtilities时,eclipse提示编译错误:

Access restriction: The type 'AWTUtilities' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')

【分析】eclipse项目默认的jre版本较早。

com.sun.awt.AWTUtilities是在JDK 6 update10中增加的。

【解决】更换JRE

方案一:为eclipse更换默认JRE

方案二:为项目更换JRE

1、项目上右击,快捷菜单,Build Path -> Configure Build Path...

2、列表树中选中Java Build Path,选项页中选中Libraries页

3、选中JRE项,Remove

4、Add Library

5、选中JRE System Library,Next

6、选中Alternate JRE,下拉列表中选择您的JRE,Finish

7、OK

 

posted on 2017-02-08 13:31  god with us  阅读(2325)  评论(0编辑  收藏  举报