代码如下:

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市场中添加e(fx)clipse。简单明了

其他回答

我只是简单地在eclipse市场中添加e(fx)clipse。简单明了

在eclipse oxygen中添加javafx可访问权限 进入项目>属性> java构建路径> libraries>,然后展开库,双击>访问规则,在那里设置权限 解决方案:无障碍 规则模式:javafx/**

我有eclipse JRE 8.112,不确定这是否重要,但我所做的是:

右键单击我的项目文件夹 点击属性 单击Java构建路径文件夹 一旦进入,我是在订单和出口 我检查了JRE系统库[jre1.8.0_112] 然后把它移到另一个JRE系统库上面(不确定这是否重要) 然后按确定

这解决了我的问题。

这种情况也发生在我身上,这里给出的答案并不令人满意,所以我自己做了研究。

背景:Eclipse访问限制

Eclipse有一种称为访问限制的机制,可以防止您意外地使用Eclipse认为不属于公共API的类。通常,Eclipse在这两方面都是正确的:我们通常不希望使用不属于公共API的东西。Eclipse通常对哪些是公共API的一部分,哪些不是公共API的一部分是正确的。

问题

有些情况下,你想使用公共非api,比如sun。杂项(你不应该这样做,除非你知道自己在做什么)。在某些情况下,Eclipse并不正确(这就是我的情况,我只想使用javax.smartcardio)。在这种情况下,我们在Eclipse中得到这个错误。

解决方案

解决方案是改变访问限制。

转到Java项目的属性, 即在“包资源管理器”的项目上下文菜单中选择“属性”。 进入“Java Build Path”,选择“Libraries”。 展开库条目 选择 “访问规则”, “编辑……” “添加……”一个带有相应规则模式的“决议:可访问”。 对我来说是“javax/smartcardio/**”,对你来说可能是“com/apple/eawt/**”。

即使它的老问题,对我来说,在Eclipse中,我只是右键单击Src文件夹和属性(Alt+Enter),检查忽略可选编译问题消除了错误。