Java 无法在Eclipse for mac中使用JFrame
我是一名编程新手,如果我使用了错误的术语,请原谅。我在macbook air上编程并使用Eclipse,但当我尝试导入javax.swing和java.awt时,它不起作用,我收到一条错误消息,请参见下面的内容。我做了很多研究,发现有些人也有类似的问题,但由于我是一个初学者,我真的不理解从项目依赖项中删除swt.jar这样的答案。如果你知道我能做些什么,我将非常感谢你的解决方案。这是我尝试的程序和出现的错误消息Java 无法在Eclipse for mac中使用JFrame,java,eclipse,macos,swing,Java,Eclipse,Macos,Swing,我是一名编程新手,如果我使用了错误的术语,请原谅。我在macbook air上编程并使用Eclipse,但当我尝试导入javax.swing和java.awt时,它不起作用,我收到一条错误消息,请参见下面的内容。我做了很多研究,发现有些人也有类似的问题,但由于我是一个初学者,我真的不理解从项目依赖项中删除swt.jar这样的答案。如果你知道我能做些什么,我将非常感谢你的解决方案。这是我尝试的程序和出现的错误消息 import java.awt.*; import javax.swing.*;
import java.awt.*;
import javax.swing.*;
class WindowTest extends JFrame
{
public WindowTest (){
super ("Hi");
setSize (300,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible (true);
Container contentArea = getContentPane();
contentArea.setBackground(Color.white);
FlowLayout flowManager = new FlowLayout();
contentArea.setLayout(flowManager);
JLabel TextLabel = new JLabel ("I am here");
contentArea.add(textLabel);
JLabel TextLabel2 = new Jlabel ("OK");
contentArea.add(TextLabel2);
JTextField textBox = new JTextField ("Write here",20);
contentArea.add(textBox);
JTextArea comments = new JTextArea ("Comments please",3,20);
contentArea.add(comments);
JButton pointlessButton = new JButton ("Exit");
contentArea.add(pintlessButton);
}
}
public class TestWindow {
public static void main(String[] args) {
WindowTest Win = new WindowTest();
}
}
以及错误消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Access restriction: The type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JFrame(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The method setDefaultCloseOperation(int) from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The field EXIT_ON_CLOSE from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The method getContentPane() from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JLabel(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
textLabel cannot be resolved
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Jlabel cannot be resolved to a type
Access restriction: The type JTextField is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JTextField(String, int) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextField is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextArea is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JTextArea(String, int, int) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextArea is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JButton is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JButton(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JButton is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
pintlessButton cannot be resolved
at WindowTest.<init>(TestWindow.java:6)
at TestWindow.main(TestWindow.java:43)
谢谢 可能是您的类所放置的目录,具有访问限制。请继续并授予您的java目录777权限。 除此之外,这并不意味着任何与mac相关的问题
您可以使用sudo chmod-R 777~directory_path是否安装了java?这是系统中JDK的权限问题。请尝试清理并重新构建您的项目。。。。项目|清洁…|大家都看到了这个类似的问题:我确实安装了Java,但我有两个不同的版本。你认为如果我卸载其中一个会有所改善吗?