代码如下:
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这样说:
应用程序访问限制:类型‘
’不是API (对所需的库'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
的限制
发布于 2015-03-29 20:42:01
这也发生在我身上,这里给出的答案已经不令人满意了,所以我做了自己的研究。
背景知识: Eclipse访问限制
Eclipse有一种称为访问限制的机制,可以防止您意外地使用Eclipse认为不是公共API一部分的类。通常,Eclipse在这两个方面都是正确的:我们通常不想使用不属于公共API的东西。Eclipse对于什么是公共API的一部分,什么不是公共API的部分通常是正确的。
问题
现在,在某些情况下,您可能想要使用公共非API,比如sun.misc
(除非您知道自己在做什么,否则不应该使用)。在某些情况下,Eclipse可能并不是真正正确的(这就是发生在我身上的事情,我只是想使用javax.smartcardio
)。在这种情况下,我们在Eclipse中会得到这个错误。
解决方案
解决方案是更改访问限制。
javax/smartcardio/**
",对你来说,可能是"com/apple/eawt/**
".。
发布于 2015-02-05 05:39:30
我也有同样的问题。当我最初在Eclipse中创建java项目时,我指定了JRE 8。当我进入项目的构建路径并编辑JRE系统库时,选择了Java 8执行环境。当我选择使用"Alernate JRE“(仍然是java8)时,它为我修复了这个错误。
发布于 2017-10-01 23:00:15
在eclipse oxygen中添加javafx辅助权限转到project> properties> java build path> libraries>,然后展开这些库并双击on> Access rules,在那里设置权限解决方案:辅助规则模式: javafx/**
https://stackoverflow.com/questions/25222811
复制相似问题