Konrad Höffner
Konrad Höffner

Reputation: 12207

NullPointerException in ControlsFX Notification

I want to show notifications to the user in my JavaFX application and chose the ControlsFX library for that purpose. However whenever I create a warning via: Notifications.create().showWarning();, I get the following Exception:

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)

This is called when my whole application is set up and visible.

Could this be a version mismatch? I use JavaFX 12 but ControlsFX only has a version 11.

This is an abbreviated version of my 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>

Upvotes: 0

Views: 413

Answers (1)

fabian
fabian

Reputation: 82461

This is a bug that is now fixed, see https://github.com/controlsfx/controlsfx/issues/1140

Unfortunately the bugfix is not included in the current release (or any release candidate: According to the version history it was fixed April 30th, 2019 but the last release was on the 19th of the same month).

Note that the code before the check for null preventing the NPE was added iterated through the window list returned by Window.getWindows() looking for a window that is focused. null is used, if no such window is found. With the current code the primary screen is used, to determine the position of the notification, if no focused window is found.

Upvotes: 3

Related Questions