嗨,我需要在Mac上使用Java的帮助。我已经完全卸载了所有版本的Java,并安装了Oracle JDK 1.8.0_202。我可以做javac和java-并编译和运行在控制台中运行的简单程序。但是-当我尝试使用窗口进行任何操作时-它会挂起。
这包括所有gui应用程序,java web启动,甚至Java控制面板也无法启动-它只是停止响应并且不显示任何内容。
此简单应用程序的行为也相同:
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
我尝试过重新安装,重新启动等操作,但仍然无法运行此简单程序。在运行此程序的终端中没有收到任何错误消息-它只是冻结。
请帮助我解决此问题并获得有效的Java设置。
我正在将Macbook pro与Mojave 10.14.3配合使用
答案 0 :(得分:1)
经过反复试验,我找到了罪魁祸首。系统完整性保护。 我已经在Mojave中禁用了SIP,而这个简单的更改使Java触发的所有窗口均失败。我再次启用了它-哇,所有的Java程序都可以再次工作。
与代码无关,与操作系统无关-因此,如果有人遇到相同问题,请尝试此操作。