【问题标题】:IllegalStateException when using the Tray Notification in java Fx?在 java Fx 中使用托盘通知时出现 IllegalStateException?
【发布时间】:2017-03-10 11:44:31
【问题描述】:

我正在尝试在 JavaFx 中实现弹出通知我正在使用这个lib 并根据该教程编写了以下代码:

    String title = "Well done boy!!";
    String message = "You've successfully created your first Tray Notification";

    TrayNotification tray = new TrayNotification();
    tray.setTitle(title);
    tray.setMessage(message);
    tray.setNotificationType(NotificationType.SUCCESS);
    tray.showAndWait();

但代码抛出异常:

原因:java.lang.IllegalStateException:工具包未初始化 在 com.sun.javafx.application.PlatformImpl.runLater(未知来源) 在 com.sun.javafx.application.PlatformImpl.runLater(未知来源) 在 com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(未知 来源)在 com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(未知 来源)在 javafx.scene.control.Control.(未知来源)... 还有 15 个

有什么建议吗?

请注意,原始代码示例为implemented like:

tray.setNotification(notification);

通知在哪里

但有些我无法导入类

 Notification notification = Notifications.SUCCESS;

【问题讨论】:

标签: java exception javafx notifications


【解决方案1】:

尝试使用构造函数进行创建。这对我有用。 您是否从模块设置中添加了库?

例如:

 TrayNotification tray = new TrayNotification("Test", "mesaj", NotificationType.SUCCESS);        
    tray.showAndWait();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 2020-05-21
    • 1970-01-01
    • 2017-05-18
    相关资源
    最近更新 更多