1

I'm trying to make a simple code that is:

import javax.swing.*;

public class Example {

    public static void main(String[] args) {

        JFrame frame = new JFrame();
    }
}

but in the line in which I instance the JFrame it gives to me an error:

Access restriction: The type JFrame is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre1.8.0_45\lib\rt.jar

I tried removing my JRE System Library of my project and adding it again but it didn't solve my problem. I saw this solution here: Access restriction on class due to restriction on required library rt.jar?

What should I do?

Thanks in advance!

Community
  • 1
  • 1
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
  • Have you checked your build path to make sure that you're using the correct version of Java and the correct JRE? – helencrump Jun 23 '15 at 21:35
  • @helencrump How can I check it? – Francisco Romero Jun 23 '15 at 21:36
  • What are you using to edit/run your code? Eclipse? – helencrump Jun 23 '15 at 21:37
  • @helencrump Yes, I am. – Francisco Romero Jun 23 '15 at 21:39
  • If you right click your project in the Project Explorer and choose Build Path -> Configure Build Path, you can see all of the libraries associated with your project. See if there's anything that shouldn't be there, or try removing the JRE System Library and re-adding it - you could try adding the workspace default library. (Apologies if you've already done this) – helencrump Jun 23 '15 at 21:43
  • @helencrump The library that I have there it's `JRE System Library [OSGi/Minimum-1.2]` but I don't know if `[OSGi/Minimum-1.2]` means it is a special library of `JRE System Library` or if it refers to the `JRE System Library` by itself. – Francisco Romero Jun 23 '15 at 21:47
  • @user2365568 it's what I said in the question that I prove before. – Francisco Romero Jun 23 '15 at 21:47
  • Why marked as duplicate? I put the question that I used for tried to solve my problem and it doesn't solved it. – Francisco Romero Jun 23 '15 at 21:49
  • My eclipse projects just show "JRE System Library" - you could try removing it under the Libraries tab of Configure Build Path, and then adding it again by choosing Add Library -> JRE System Library -> Workspace Default. (Again, apologies if you've done this) – helencrump Jun 23 '15 at 21:49
  • Because that *is* the solution -- this is an Eclipse issue and you need to fix it as per all the similar duplicates to this question. – Hovercraft Full Of Eels Jun 23 '15 at 21:50
  • @HovercraftFullOfEels But it didn't fix my problem as I put in my question. What should I do? I tried to use the answers to both questions (the question that you match that it's duplicate of the question that I put in my question). – Francisco Romero Jun 23 '15 at 21:51
  • @helencrump When I try to add again I have 3 options: choose an execution environment, alternate JRE and workspace default JRE (jre1.8.0_45). What should I use? – Francisco Romero Jun 23 '15 at 21:54
  • 1
    I'd go for the workspace default. – helencrump Jun 23 '15 at 21:54
  • @helencrump Well... I don't know why (because I did the same process before, choosing `Workspace default` option) but now it doesn't give me any problem. Thanks for the help provided! – Francisco Romero Jun 23 '15 at 21:57
  • @Error404 Happy to help :) – helencrump Jun 23 '15 at 21:58
  • [Google search](https://www.google.com/?gws_rd=ssl#q=eclipse+restricted+due+to+restriction+on+required+library) – Hovercraft Full Of Eels Jun 23 '15 at 22:06
  • @HovercraftFullOfEels It's the first solution that I tried. You get the same results if you put in Google the error by copy-paste (without the path) but anyway now I could solve it. Thanks for the help! – Francisco Romero Jun 23 '15 at 22:13

0 Answers0