代码如下:

package mscontroller;

import javax.swing.*;
import com.apple.eawt.Application;

public class Main {
    public static void main(String[] args)
    {
        Application app = new Application();
        app.setEnabledAboutMenu(true);

        AMEListener listener = new AMEListener();
        app.addApplicationListener(listener);
        JFrame mainFrame = new JFrame("Application Menu Example");
        mainFrame.setSize(500, 500);
        mainFrame.setVisible(true);
    }
}

错误如下:

Exception in thread "main" java.lang.Error: Unresolved compilation
problems:   Access restriction: The type 'Application' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The constructor 'Application()' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The type 'Application' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The method
'Application.setEnabledAboutMenu(boolean)' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    AMEListener cannot be resolved to a type    AMEListener cannot be
resolved to a type

    at mscontroller.Main.main(Main.java:9)

Eclipse说:

访问限制:'Application'类型不是API(对必需库'/ library /Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar'的限制)


当前回答

删除现有/配置的系统库: Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries -> (Select) JRE System Library [(For me)jre1.8.0_231] -> Remove。

目前你在同一位置: Eclipse(IDE) ->项目资源管理器->项目名称->(选项)构建路径->配置构建路径-> Java构建路径->库

现在再次添加相同的系统库: Add Library -> JRE System Library -> Workspace default JRE ((For me)jre1.8.0_231) -> Finish -> Apply -> Close

现在等着完成它。

其他回答

我也有同样的问题。以下是我的解决方法: 进入包资源管理器。右键单击JRE系统库,然后进入属性。在类路径容器>中为项目构建路径选择JRE,选择第三个选项(工作区默认JRE)。

来源:https://thenewboston.com/forum/topic.php?id=3917

我也有同样的问题。当我最初在Eclipse中创建java项目时,我指定了JRE 8。当我进入项目的构建路径并编辑JRE系统库时,选择了Java 8执行环境。当我选择使用“Alernate JRE”(仍然是java 8)时,它为我修复了这个错误。

删除现有/配置的系统库: Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries -> (Select) JRE System Library [(For me)jre1.8.0_231] -> Remove。

目前你在同一位置: Eclipse(IDE) ->项目资源管理器->项目名称->(选项)构建路径->配置构建路径-> Java构建路径->库

现在再次添加相同的系统库: Add Library -> JRE System Library -> Workspace default JRE ((For me)jre1.8.0_231) -> Finish -> Apply -> Close

现在等着完成它。

我们使用IBM Rational Application Developer (RAD),也遇到了同样的问题。

ErrorMessage:

访问限制:'JAXWSProperties'类型不是API(对必需库'C:\IBM\RAD95\jdk\jre\lib\rt.jar'的限制)

解决方案:

进入java构建路径,在Library标签下,删除JRE System Library。然后再次添加库—> JRE系统库

我遇到这个问题是因为与我的项目相关联的项目方面是错误的java版本。

为了解决这个问题,我做了以下工作:

右键单击项目并选择Properties 选择“Project Facets”,将java版本更改为大于1.4的版本。 点击【应用】

这将重新构建您的项目,希望错误将得到解决。