【发布时间】: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;
【问题讨论】:
-
是否调用 Platform.runLater 中的代码?
-
不,在 eclipse 的 main 方法中,代码按照上面发布的示例运行......
-
子类
Application或创建一个新的new JFXPanel()以初始化工具包。见stackoverflow.com/questions/11273773/… 和stackoverflow.com/questions/14025718/…
标签: java exception javafx notifications