Access restriction in Eclipse: the type ‘xxx’ is not API solution

To report this error, you only need to change the JRE under the JDK path to an external JRE

Project – & gt; properties – & gt; Java build path – & gt; libraries, select JRE system library, and then remove. Then click Add Library – & gt; JRE system library – & gt; next, select alternate JRE, click installed jres, select JRE under the same level directory of JDK, and then click Apply – & gt; OK.

Learn about the role of two jres in Java: (the following is from http://blog.sina.com.cn/s/blog_ 7ffb8dd501011 sgc.html )

1. In the bin directory of JDK java.exe With external JRE java.exe The secret of
JDK java.exe And in JRE java.exe In fact, it’s the same, but we use external JRE in priority when running java.exe (even if we install JDK and configure environment variables).
first of all, let’s see what happened during the installation of JDK:
when installing JDK, you will install a JRE under its subdirectory. At the same time, you will be asked whether you want to install an external JRE during the installation process. If we choose to install, we have two jres at the same time. In fact, there is no difference between the two jres. The main difference is that the JRE in the JDK directory is mainly designed to run the tools that come with JDK (under the bin directory). The external JRE will automatically register to the path of the operating system when it is installed (but the path value of the command is not included in the path in my computer, properties, advanced system settings, environment variables and system variables). In general, it is in the system32 folder (the folder contains: java.exe javaw.exe javaws.exe Three files). Therefore, as long as we install external JRE (even if JDK is not installed and environment variables are not configured), we will use external JRE when running Java programs java.exe Program (even if JDK is installed and environment variables are configured) (the default path of the system has priority).  

2.
in short, JDK is an SDK for developers. SDK is a software development kit, which generally refers to software development kit, including function library, compiler, etc.
JDK (java development kit) provides java development environment and running environment, which is mainly used to develop java programs for Java program developers;
JRE (Java runtime environment) provides Java running environment, which is mainly used to execute Java programs for Java program users.
generally, each JDK contains two sets of jres. With JDK jdk1.6.0_ 22 (the default installation path is e: / / program files / Java), for example, in E: / / program files / Java / jdk1.6.0_ There is a JRE in the directory of 22, and there is also a JRE in the directory of C: program files. Why are there two jres? Because the tools in JDK are also written in Java, they also need a set of JRE when they are running, that is, e: \ “program files \” Java \ “jdk1.6.0_ 22 \ \ JRE under the directory. The JRE in the directory e: program files: Java is used to execute our own Java program. Of course, any one of the two sets of jres can be used to execute our own Java programs, but the tools in JDK can only be used by E: / / program files / Java / jdk1.6.0_ 22 \ \ directory.
since there are at least two sets of jres in our computers (if Borland JBuilder and other advanced development tools are installed, there will be more sets of jres in our computers), who will decide which set of jres to use? The burden falls on us java.exe On my body. (of course, when JDK is installed in 1, the external JRE is executed by default!)
when we enter:
java XXX
on the command line, java.exe Our task is to find the right JRE to execute XXX among the many jres on our computer. java.exe Search for jres in the following order:
(1) whether there is a JRE directory in your own directory;
(2) whether there is a JRE directory in your parent directory;
(3) query the registry HKEY_ LOCAL_ Machine / software / javasoft / Java runtime environment java.exe What is the difference between the results of the implementation and those in our computer java.exe (a search will reveal that there is more than one in our computer java.exe )It has a lot to do with the execution and which JRE will execute the JVA program.
in addition, java.exe After finding the right JRE, there is a verification version of the program, that is java.exe It can only be executed if it is consistent with the JRE version. If there is a version inconsistency problem, we must remember two things:
(1) which one java.exe Executed;
(2) java.exe Find out which JRE.
as long as these two things are determined, we will grasp the whole process of the problem and solve it easily.
3,
JVM (Java virtual machine) is a part of JRE, and JRE is the supplement of JVM. So where is the JVM? We can open C: / / program files / Java / JDK1.5. X / JRE / bin to see two directories: client and server. You can see them in these two directories jvm.dll This is what we call the JVM.

Read More: