2

I'm trying to migrate to Java 17 from Java 8 over X2Go client and when I try to run a simple code that includes GUI, even dialog with 1 button, this exception is thrown:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "sun.awt.X11.XBaseWindow.isVisible()" because "parent" is null
            at java.desktop/sun.awt.X11.XWindowPeer.setToplevelTransientFor(XWindowPeer.java:1688)
            at java.desktop/sun.awt.X11.XWindowPeer.postInit(XWindowPeer.java:253)
            at java.desktop/sun.awt.X11.XDecoratedPeer.postInit(XDecoratedPeer.java:105)
            at java.desktop/sun.awt.X11.XBaseWindow.init(XBaseWindow.java:184)
            at java.desktop/sun.awt.X11.XBaseWindow.<init>(XBaseWindow.java:259)
            at java.desktop/sun.awt.X11.XWindow.<init>(XWindow.java:147)
            at java.desktop/sun.awt.X11.XComponentPeer.<init>(XComponentPeer.java:111)
            at java.desktop/sun.awt.X11.XCanvasPeer.<init>(XCanvasPeer.java:42)
            at java.desktop/sun.awt.X11.XPanelPeer.<init>(XPanelPeer.java:48)
            at java.desktop/sun.awt.X11.XWindowPeer.<init>(XWindowPeer.java:134)
            at java.desktop/sun.awt.X11.XDecoratedPeer.<init>(XDecoratedPeer.java:62)
            at java.desktop/sun.awt.X11.XDialogPeer.<init>(XDialogPeer.java:40)
            at java.desktop/sun.awt.X11.XToolkit.createDialog(XToolkit.java:1084)
            at java.desktop/java.awt.Dialog.addNotify(Dialog.java:768)
            at java.desktop/java.awt.Window.pack(Window.java:829)

I had no such problems in Java 8 and I couldn't find any hint that could solve this.

It doesn't occur when running in KDE mode only when the session is in single application mode. The OP is centOS 7.8.

Thanks in advance.

EDIT: As described in the Java-doc of JDialog: To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

This solves dialogs that are visible before the main frame. (i.e splash screen, password request etc.)

EDIT 2: For JOptionPane, calling to JOptionPane#setRootFrame(main_program) will prevent the exception and will provide the given parent.

This solves JOptionPane in case there is already opened Window visible.

  • 2
    I have the exact same issue with Intellij IDEA on Ubuntu, so this seems to be not related to eclipse or CentOS. Staring a single-application x2go session for Intellij, I get the same exception when running a Swing application from that Intellij session. – OhleC Feb 06 '23 at 14:44
  • The problem in my case was that the splash screen was JDialog and the main application (JFrame) wasn’t fully loaded. Possible fix for that was to change the splash screen to extend JFrame instead – Michael Azarzar Feb 07 '23 at 15:10
  • Thanks, I figured something like that. The application I'm working with is quite large, and instantiates (but mostly doesn't yet show) several dialogs before the main frame is shown. This is not a problem unless started from an x2go single-application session running the IDE. – OhleC Feb 09 '23 at 08:30
  • Can you share a minimal reproducible example that others can work with, so we can see the issue and answer accordingly? E.g. a maven project with just x2, AWT, and a frame/window that causes this. – Rogue Feb 10 '23 at 16:41
  • @Rogue Just a simple `JOptionPane.showConfirmDialog(null, "hello")` in `main` is enough. Start it locally, you get a dialog. Start it from an IDE session run as x2go single-application, you get the exception from the question. – OhleC Feb 12 '23 at 15:10
  • I get the same with PyCharm and CLion. I even reported it to JetBrains some time ago: https://youtrack.jetbrains.com/issue/PY-56927 – peper0 Jun 21 '23 at 07:07

0 Answers0