package com.shijianchuli; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Demo1 extends JFrame{ MyPanel mp = null; public static void main(String[] args) { // TODO Auto-generated method stub } } class MyPanel extends JPanel{ public void paint(Graphics g) { } }
这只是个初始程序,但出现这样的错误提示:
Accessrestriction: The type JFrame is not accessible due to restriction on requiredlibrary D:\Program Files\Java\jre7\lib\rt.jar
问题原因:Eclipse 默认把这些受访问限制的API设成了ERROR
解决方法:
1. Windows-> Preferences -> Java -> Compiler -> Errors/Warnings ->Deprecatedand trstricted API -> Forbidden reference (access rules): -> change towarning
2. 只需要在projectbuild path中先移除JRESystem Library,再添加库JRESystem Library,重新编译后就一切正常了。
3. 工程上右键->工程属性->javabuilder path->Libraries标签,点击JRE SystemLibrary里面的Accessrules,addsun/** 为accessible,如果该项存在,就edit。
4. Windows-> Preferences -> Java -> Installed JREs -> 选择用的JDK-> Edit -> Add External JARs
测试结果(MyEclipse):
解决方法1可行