我正在使用 IntelliJ IDEA 并编写了一个非常基本的 JavaFX 程序(或者实际上刚刚开始编写该程序)。当我运行程序来检查 GUI,然后点击 X 按钮关闭 java 窗口时,我得到以下信息。如果我编写一个按钮来表示 Platform.exit() 它也会给我以下代码:
Process finished with exit code -1073741819 (0xC0000005)
我编写了一个按钮来调用 System.exit(0),当我单击它时,它会在控制台上打印出退出按钮被单击的信息,然后显示:
The Java SE Binary has stopped working.
我在 Intellij IDEA 中启动了一个新的 JavaFX 项目,然后点击运行来检查它运行的基本示例窗口,并且该窗口也以上面列出的退出代码退出。
我安装了最新的 JDK(jdk1.8.0_121 64 位)、GluonHQ 的最新版本的 scenebuilder,并且正在运行 Windows 10 Pro x64。
不确定还需要提供什么信息,如果您需要更多信息,请告诉我。
退出按钮的代码(fxid 与controller/.xml 文件中的相同)。我计划将来做一个 lambda,仍然围绕着这些,但这应该按原样工作,不是吗?
exitButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("You clicked exit!");
Platform.exit();
}
});
编辑:这代码本身就是您启动新的 JavaFX 项目时 IntelliJ IDEA 创建的示例项目。在没有任何调整的情况下,我仍然得到退出代码而不是预期的 0,因此发生的事情与我编写的代码无关。
在示例.fxml 上
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
在Controller.java
package sample;
public class Controller {
}
在Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
最佳答案
根据various sources ,这似乎是一系列 NVidia 驱动程序的问题。我收到返回代码 0xC0000005
,将我的驱动程序更新至 378.66(2017 年 2 月 13 日发布,截至 2017 年 2 月 21 日)并不再遇到此问题。
关于java - 基本 Java 应用程序因错误退出代码而关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096966/