在JavaFX Windows应用程序上故意重现应用程序崩溃“应用程序已停止工作”

时间:2018-02-07 10:27:19

标签: java windows javafx javafx-8

我正在为 Windows 专门编写 JavaFX 应用,其中应用需要崩溃并生成通用"Application has Stopped Working" 错误对话< / strong>当客户端使用盗版序列密钥激活应用时,看到here

这可能吗?

1 个答案:

答案 0 :(得分:1)

您可以将Alert类与ERROR警报类型一起使用 以下是一个工作示例:

<强> MyApplication.java

FileReader fileReader = new FileReader(this);
final Map<String, String> numberDescMap = fileReader.ExcelFileReader();

<强> ApplicationError.java

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    try {
        // do something
        throw new RuntimeException();
    } catch (Exception ex) {
        displayApplicationError();
    }

}

private void displayApplicationError() {
    Platform.runLater(() -> {
        new ApplicationError().start(new Stage());
        Platform.exit();
    });
}

enter image description here

警报在Windows上具有原生外观,您可以找到更多示例here