Trouble debugging Java FX 21 app

Answered

First, let me say, I am a beginner with java and have inherited an app.  We wanted to update the app from Java 17 to Java 21.  The app will run on Windows and Linux, but I am running IntelliJ on Windows.  Also, the app uses JavaFX.  The good news, we got it updated and it builds on our build server using Maven and the JAR works.  However, I cannot debug it in IntelliJ.  When I try to debug it, I get this exception:

java.lang.ClassNotFoundException: com.sun.glass.ui.win.WinPlatformFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:421)
	at java.base/java.lang.Class.forName(Class.java:412)
	at javafx.graphics@21.0.6/com.sun.glass.ui.PlatformFactory.getPlatformFactory(PlatformFactory.java:42)
	at javafx.graphics@21.0.6/com.sun.glass.ui.Application.run(Application.java:146)
	at javafx.graphics@21.0.6/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:290)
	at javafx.graphics@21.0.6/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:292)
	at javafx.graphics@21.0.6/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1149)
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:115)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1149)
Caused by: java.lang.NullPointerException: Cannot invoke "com.sun.glass.ui.PlatformFactory.createApplication()" because the return value of "com.sun.glass.ui.PlatformFactory.getPlatformFactory()" is null
	at javafx.graphics@21.0.6/com.sun.glass.ui.Application.run(Application.java:146)
	at javafx.graphics@21.0.6/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:290)
	at javafx.graphics@21.0.6/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:292)
	at javafx.graphics@21.0.6/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
	at javafx.graphics@21.0.6/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	... 2 more

Googling “getPlatformFactory is null” returned no helpful information.  The debug configuration has these VM Options:

--module-path="C:/Temp/javafx-sdk-21.0.6/lib" --add-modules="javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing" --add-reads javafx.graphics=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED --add-reads javafx.base=ALL-UNNAMED --add-opens javafx.base/com.sun.javafx.logging=ALL-UNNAMED --add-opens javafx.base/com.sun.javafx.logging=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.embed=ALL-UNNAMED

I am posting this here because the Maven produced Jar works - even if built from IntelliJ.  I just can't debug with IntelliJ.

Any help would be greatly appreciated.

Thanks

0
5 comments

no one has any ideas?

0

I ended up deleting module-info.java and debugging started working.  Obviously, I won't check that change into source control, but at least I can debug again.  hope this helps someone.

0
Thanks for the update. I'll try to reproduce and create an issue report for this.
0
Thanks for the update. I'll try to reproduce and create an issue report for this.
0

Hi Steve,

I've tried to set up a Gradle/JavaFX 21 project but failed to reproduce it, debug with the Gradle's run task. Could you please provide a minimal sample project so I can reproduce the issue without including your sensitive code? Thank you! Please upload it to https://uploads.jetbrains.com/ and paste the upload id here. The uploaded file is only visible to JetBrains employees.

 

build.gradle

plugins {
    id 'java'
    id 'application'
    id 'org.javamodularity.moduleplugin' version '1.8.12'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.10.0'
}

sourceCompatibility = '21'
targetCompatibility = '21'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'org.example.javafxhello'
    mainClass = 'org.example.javafxhello.HelloApplication'
}

javafx {
    version = '21.0.6'
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', 'javafx.swing', 'javafx.media']
}

dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
    testImplementation("org.junit.jupiter:junit-jupiter-params:${junitVersion}")
}

test {
    useJUnitPlatform()
}

jlink {
    imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'app'
    }
}

jlinkZip {
    group = 'distribution'
}

 

mofule-info.java

module org.example.javafxhello {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.web;


    opens org.example.javafxhello to javafx.fxml;
    exports org.example.javafxhello;
}
0

Please sign in to leave a comment.