An exception is in MouseInfo.getPointerInfo (). GetLocation ()

I use JavaFX and Swing in my graphics application. In more detail, I use SwingNode on top of AnchorPane to add a JPanel, and some map on it (ARCGIS JMap - only works on a swing), which is constantly updated.

When I drag my application between two screens, I have one NullPointerException.

This is the Java code where this happens:

MouseInfo.getPointerInfo().getLocation()

Drag and drop is performed on the JavaFX element (event - JavaFX event):

    private void setDraggable(Parent root) {
    if (root != null) {
        root.setOnMousePressed((event) -> {
            xOffset = mainStage.getX() - event.getScreenX();
            yOffset = mainStage.getY() - event.getScreenY();
        });

        root.setOnMouseDragged((event) -> {
            mainStage.setX(event.getScreenX() + xOffset);
            mainStage.setY(event.getScreenY() + yOffset);
        });
    }

But the exception occurs in the AWT thread.
As I said, the code where it crashes (note that this is Java internal code, not mine):

MouseInfo.getPointerInfo().getLocation()

What can I do to prevent this?

, , - , Swing (JPanel JMap) JComponent. JLightweightFrame. ?

:

Message = Thread AWT-EventQueue-0 (Id = 45) throw exception: null Stack-Trace = java.lang.NullPointerException
    at sun.swing.JLightweightFrame.updateClientCursor(JLightweightFrame.java:473)
    at sun.swing.JLightweightFrame.access$000(JLightweightFrame.java:79)
    at sun.swing.JLightweightFrame$1.updateCursor(JLightweightFrame.java:112)
    at sun.awt.windows.WLightweightFramePeer.updateCursorImmediately(WLightweightFramePeer.java:92)
    at java.awt.Component.updateCursorImmediately(Component.java:3150)
    at java.awt.Container.validate(Container.java:1642)
    at java.awt.Window.dispatchEventImpl(Window.java:2748)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
+4

Source: https://habr.com/ru/post/1659599/


All Articles