首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NullPointerException中的ControlsFX通知

NullPointerException中的ControlsFX通知
EN

Stack Overflow用户
提问于 2019-08-22 15:34:51
回答 1查看 370关注 0票数 0

我想在我的JavaFX应用程序中向用户显示通知,并为此选择了ControlsFX库。但是,每当我通过:Notifications.create().showWarning();创建警告时,就会得到以下异常:

代码语言:javascript
复制
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的简写版本

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-22 16:32:42

这是一个现在已修复的bug,请参阅https://github.com/controlsfx/controlsfx/issues/1140

不幸的是,目前的版本(或任何版本候选版本:根据版本历史,它是固定的2019年4月30日,但最后一个版本是在同一个月的19日)。

请注意,检查防止nullWindow.getWindows()之前的代码是通过Window.getWindows()返回的窗口列表来迭代的,以寻找一个焦点集中的窗口。如果没有找到这样的窗口,则使用null。在当前代码中,如果没有找到焦点窗口,则使用主屏幕来确定通知的位置。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57612837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档