我想在我的JavaFX应用程序中向用户显示通知,并为此选择了ControlsFX库。但是,每当我通过:Notifications.create().showWarning();创建警告时,就会得到以下异常:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at org.controlsfx.controls/org.controlsfx.control.Notifications$NotificationPopupHandler.getScreenBounds(Notifications.java:364)
at org.controlsfx.controls/org.controlsfx.control.Notifications$NotificationPopupHandler.show(Notifications.java:343)
at org.controlsfx.controls/org.controlsfx.control.Notifications.show(Notifications.java:305)
at org.controlsfx.controls/org.controlsfx.control.Notifications.showWarning(Notifications.java:271)当我的整个应用程序被设置并可见时,就会调用它。
这可能是版本错配吗?我使用JavaFX 12,但ControlsFX只有11版本。
这是我的pom.xml的简写版本
<project xmlns="[...]">
[...]
<properties>
<maven.compiler.release>12</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>eu.snik.tag.gui.Main</mainClass>
</configuration>
[...]
</plugin>
</plugins>
[...]
<dependencies>
[...]
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.0.0</version>
</dependency>
</dependencies>
</project>发布于 2019-08-22 16:32:42
这是一个现在已修复的bug,请参阅https://github.com/controlsfx/controlsfx/issues/1140
不幸的是,目前的版本(或任何版本候选版本:根据版本历史,它是固定的2019年4月30日,但最后一个版本是在同一个月的19日)。
请注意,检查防止null的Window.getWindows()之前的代码是通过Window.getWindows()返回的窗口列表来迭代的,以寻找一个焦点集中的窗口。如果没有找到这样的窗口,则使用null。在当前代码中,如果没有找到焦点窗口,则使用主屏幕来确定通知的位置。
https://stackoverflow.com/questions/57612837
复制相似问题