So I know similar questions have been asked multiple times, but I've tried about everything I found, yet I just can't seem to figure this out.
Im trying to make this simple JavaFX sample work: https://openjfx.io/openjfx-docs/#install-javafx
I'm using IntelliJ and Gradle, I followed the instructions but whenever I try to run the program in IntelliJ it gives me the "Location is required" error on my FXMLLoader.
From what i gathered, it should work by putting the scene.fxml file in the resource directory, but that doesn't seem to work for me. I've also tried putting the scene.fxml in the same package as MainApp, still didnt work.
EDIT I just noticed the Gradle build output seems to work fine. It's only a problem when i try to run my code inside IntelliJ.
So I tried another JavaFX Project without Gradle. In that case, IntelliJ creates an "out" directory which is structured the same way as my project. When using Gradle, a "build" directory is created which does contain the fxml, but not at the location I'm expecting?
This is my Main Class:
package org.openjfx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/scene.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("JavaFX Test");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args){
launch(args);
}
}
The build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.15.1'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.12
repositories {
mavenCentral()
}
javafx {
version = "12.0.2"
modules = ['javafx.controls', 'javafx.fxml']
}
mainClassName = "$moduleName/org.openjfx.MainApp"
jlink{
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'hellofx'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
And this is what my project structure looks like: