Java students working on projects, especially GUI projects with Swing controls, may see a variety of strange errors including things like:
- Access restriction: The contructor JFrame() is not accessible due to restriction on required library C:\Program Files\Java\jre1.8.0_11\lib\rt.jar
- Access restriction: The type JFrame is not accessible due to restriction on required library C:\Program Files\jre1.8.0_111\lib\rt.jar
These errors may be caused by selecting the wrong JRE when creating the Java project. Take a close look at your program in the Eclipse Package Explorer:
See how it says your JRE System Library is “CDC-1.1/Foundation-1.1” ? That is incorrect – you should be using the JRE 1.7 or 1.8 that is installed on your computer. When you create a new Java Project…
Make sure you have selected “Use Default JRE” under the JRE section, and that that JRE is something like “jre_1.8.X” or “jre_1.7.X” depending on what you have installed. Do not select "CDC-1.1/Foundation" for the JRE, which is an unusual setting that will cause multiple problems.
You can fix an existing project by right-clicking on the project name in the Package Explorer and selecting “Properties”, then “Java Build Path” and click on the “Libraries” tab. Select your CDC/Foundation line and click “Remove”, then click “Add Library” and select your JRE 1.8 or 1.7 library. That should fix it!