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'
}