0

I am trying to create an example with JFrame, but when i write JFrame in eclipse, it gets underscored by red line as if it is not defined, how can I solve this issue:

code:

package openCVExamples;

public class OpenCVTest {

  public static void main(String[] args) {
    JFrame j = new JFrame();        
  }
} 

update:

when hover over JFrame keyword, eclipse says

:Access restriction: the type     
JFrame is not accessible due to restriction on required library 
c:?\programfiles\java\jre1.8.0_40\lib\rt.jar 
GhostCat
  • 137,827
  • 25
  • 176
  • 248
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    Please copy/paste your code here. – tdebroc Mar 24 '15 at 09:23
  • @lisztomania the code posted – Amrmsmb Mar 24 '15 at 09:36
  • When I paste your code in my eclipse ... JFrame is underlined; then I press "ctrl-shift-o"; the import statement is added and the red line is added. So, next step: turn to the "problems" view and copy/paste the error message you get for the import statement here. – GhostCat Mar 24 '15 at 09:44
  • http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar – Rohit Rehan Mar 24 '15 at 10:00
  • Or if that thing somehow vanished into thin air - consider deleting the question. – GhostCat Sep 01 '17 at 18:59

3 Answers3

0

Most likely; you did not import the JFrame class.

You can simply press "ctrl-shift-o" to "organize" your import statements. Eclipse will automatically add all required imports.

JFrame is a class that belongs to the "default" set of classes for Java. If it can't be found/imported, then your "project setup" is broken somehow.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • import javax.swing.*; i unrecognisable by eclipse as well – Amrmsmb Mar 24 '15 at 09:29
  • Then your project is somehow broken. You could try the **2nd** answer given here: http://stackoverflow.com/questions/9266632/access-restriction-is-not-accessible-due-to-restriction-on-required-library – GhostCat Mar 24 '15 at 10:00
0

You have to import the JFrame class. You can write:

package OpenCVExamples;

import javax.swing.*;

public class OpenCVTest{
     //your code
}

at the top of your file, but after the package line.

You can also do it automatically by pressing Ctrl+Shift+O to import all the classes you need.

fonfonx
  • 1,475
  • 21
  • 30
  • import javax.swing.*; i unrecognisable by eclipse as well – Amrmsmb Mar 24 '15 at 09:29
  • Normally when you begin to write import javax. the eclipse editor proposes you a list of choices including javax.swing.* That is pretty weird that eclipse does not recognize it. Are you sure you have no syntax errors before this line? – fonfonx Mar 24 '15 at 09:36
  • when you pass your mouse pointer on the red lines of JFrame, does the editor proposes you a solution? – fonfonx Mar 24 '15 at 09:37
  • Then you should write the import line after the package line. – fonfonx Mar 24 '15 at 09:39
  • when hover over JFrame keyword, eclipse says :Access restriction: the type JFrame is not accessible due to restriction on required library c:?\programfiles\java\jre1.8.0_40\lib\rt.jar – Amrmsmb Mar 24 '15 at 09:52
0

Project -> Properties -> Libraries

Remove the rt.jar file

Click on "Add external JARs.."

Re-add the rt.jar file (located at C:\Program Files\Java\jre1.8.0_20\lib)

If it still does not work, you might want to try a different Java Runtime Environment. I had the same problem and what fixed it for me was importing the rt.jar file located at C:\Program Files\Java\jre7\lib.

Community
  • 1
  • 1
Tom O
  • 2,495
  • 2
  • 19
  • 23