Access restriction problem in Eclipse

Eclipse error message:
Access restriction: Class is not accessible due to restriction on required library

Solution 1 (dirty)

This error message can be removed by changing a setting inside Eclipse IDE. Open up the dialog box shown below, using any of the following paths.

  1. Windows → Preferences → Java → Compiler → Errors/Warnings
  2. (Project) Properties → Java Compiler → Errors/Warnings

Locate the «Forbidden reference (access rules)» option under «Deprecated and restricted API» section in the dialog box. This option decides how to handle access rules defined inside Eclipse. By default it is set to «Error» which causes Eclipse to complain about references to any restricted classes. Choosing any other option (Warning or Ignore) will remove these error messages.

«Warning» or «Ignore» options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules. To completely resolve this issue, analyze the project and located the use of restricted classes and take necessary actions (either remove those references or access rules).

Solution 2 (nice)

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select «Add Library» and select the JRE System Library.

The default has worked for my friends as well. It works because we have multiple classes in different jar files. Removing and re-adding the jre lib will make the right classes be first.

dev/java/tips/accessrestrict.txt · Последние изменения: 2012/09/23 20:56 — jamis7005
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0