1

I'm working on a IntelliJ plugin project using Java, JavaFX, and Gradle.

I can successfully create JavaFX elements programmatically. If I attempt to use fxml files and the FXMLLoader the plugin fails due to javafx.fxml.LoadException: JavaFX Class is not a valid type errors. I'm suspicious this is a simple dependency issue with gradle but I'm running in circles at this point. So my main question is why does programmatically building JavaFX classes work but using FXMLLoader does not.

If additional information is required I'll happily share it - just let me know. Below is what I think is relevant. Thanks for any help.

Exception message:

javafx.fxml.LoadException: HBox is not a valid type.
file:/D:/Projects/IU-P532-Assignments/FinalProject-Team3/build/idea-sandbox/plugins/p532.fall21.finalproject.team3/lib/p532.fall21.finalproject.team3-1.0-SNAPSHOT.jar!/HeatMapScene.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2621)
    at javafx.fxml.FXMLLoader.createElement(FXMLLoader.java:2789)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2719)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
    at intellij_extension.TestToolWindowFactory.lambda$createToolWindowContent$0(TestToolWindowFactory.java:32)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:829)

Here's a snippet of the code:

        //Load in the XML of the test window
        // This throws exception
        Parent playRoot = FXMLLoader.load(getClass().getClassLoader().getResource("HeatMapScene.fxml"));

        // This will work properly
        Parent playRoot = new HBox();

Here's the fxml file:

<?xml version="1.0" encoding="UTF-8"?>


<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<HBox id="hboxHeatMapSceneRoot" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
      prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
        <FlowPane id="flowPnHeatFileContainer" prefHeight="400.0" prefWidth="420.0"/>
    </children>
</HBox>

Here's my build.gradle file:

plugins {
    id 'java'
    id 'org.openjfx.javafxplugin' version '0.0.7'
    id 'org.jetbrains.intellij' version '1.2.1'
}

group 'p532.fall21.finalproject.team3'
version '1.0-SNAPSHOT'

sourceCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
    version = '2021.2.3'
}

runIde {
    jvmArgs = [
            '--add-exports',
            'java.base/jdk.internal.vm=ALL-UNNAMED'
    ]
}

patchPluginXml {
    changeNotes = """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}
test {
    useJUnitPlatform()
}

javafx {
    modules = ['javafx.controls', 'javafx.fxml']
    version = '11.0.2'
}


DuxClarus
  • 159
  • 1
  • 3
  • 12
  • I can't reproduce your issue, it works in my environment. – jewelsea Oct 30 '21 at 22:01
  • Here is a [tutorial on locating and finding resources](https://edencoding.com/where-to-put-resource-files-in-javafx/) and some [stackoverflow references](https://stackoverflow.com/questions/19602727/how-to-reference-javafx-fxml-files-in-resource-folder). It could be that you are just picking up the wrong version of the file somehow (to debug, before loading, get the fxml resource as text and output it to system out to see what its contents are). But you may have some other issue (I use maven for builds not gradle, so I can't really help you troubleshoot that). – jewelsea Oct 30 '21 at 22:06
  • Thanks for the info; I'll look into it. My team prefers Maven but Intellij recommends gradle for plugin projects so we are running with that for two reasons. One its their recommendation and two why not try and learn a new tool. – DuxClarus Oct 31 '21 at 15:15

1 Answers1

0

I had the same issue and couldn't figure it out after a few hours of searching.

Eventually i discovered that JavaFX is no longer supported in Intellij: https://blog.jetbrains.com/platform/2020/07/javafx-and-jcef-in-the-intellij-platform/

Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61