Error Access restriction: The type is not accessible

1

I'm trying to develop a simple screen in java using JFrame but in my eclipse it's showing a message in JFrame .

  

Access restriction: The construction JFrame (String) is not accessible   due to restriction on required library   usr / lib / jvm / java-8-openjdk-amd64 / jre / lib / rt.jar

     

Access restriction: The JFrame type is not accessible due to   restriction on required library   usr / lib / jvm / java-8-openjdk-amd64 / jre / lib / rt.jar

My eclipse is in Linux Mint 18.3 (Sylvia)

My code:

package view;
import javax.swing.*;
public class TelaInicial {


    private void construirJanela(){

        JFrame janela = new JFrame("Janela");
        janela.setVisible(true);

    }

}

My java looks like this:

carlos@carlos /usr/lib/jvm $ java -version
openjdk version "1.8.0_162"
OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)
    
asked by anonymous 06.04.2018 / 01:39

1 answer

2

As this answer in SOEn , you can try the following:

  • Right click on the project and select Properties ;
  • Go to " Java Build Path " and remove the "JRE System Library"
  • Read it by clicking " Add Library ".

The likely reason for this error should be class conflicts with similar names in different libraries added in the project. By reading system jar, you reorder this jar to the top of the list to be queried when importing a class with a similar name.

    
06.04.2018 / 12:56