#"Location is required" error in JavaFX despite giving location
1 messages · Page 1 of 1 (latest)
<@&987246487241105418> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
package com.example.mygame;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.*;
public class HelloApplication extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("/screen.fxml"));
Scene scene = new Scene(root);
stage.setWidth(500);
stage.setHeight(350);
stage.setResizable(false);
stage.setTitle("My Anagram Game");
stage.setScene(scene);
stage.show();
}
}
show file tree in build folder
this?
build folder
in classes
show resources
try to build again
is that the same thing as running the program?
no
nothings happening
nothing in the console ?
delete the whole folder?
yes
did you delete it ?
yes
because build doesn't really match your file tree
try to actually run gradlew clean build
where do I go to input that
this?
can you show the file tree above ?
.idea?
this
weird 🤔
yes
hm
can you try to put screen.fxml in com.example.mygame
done
then clean and build again
show build.gradle
build.gradle
oh myb
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 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.9.2'
}
sourceCompatibility = '20'
targetCompatibility = '20'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example.mygame'
mainClass = 'com.example.mygame.HelloApplication'
}
javafx {
version = '20'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
implementation('com.dlsc.formsfx:formsfx-core:11.6.0') {
exclude(group: 'org.openjfx')
}
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${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'
}
I don't know why it doesn't copy screen.fxml sorry
i appreciate the help regardless
wait for someone else how knows better about gradle then me I guess
is it normal that he has 2 gradle versions ?
lets see
@hard marsh
ill fix it
based on rhcp.png
had the exact same issue with rhcp.png not showing
and he said it still didn't work
i didnt run the program with it inside
resources is marked as resource ? just to be sure
what does this mean
I think so based on the fact that rhcp.png is inside the build folder
rhcp is in com though, even on the older shots
its not?
same level as com, sorry
yeah
package com.example.mygame;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.*;
public class HelloApplication extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("/screen.fxml"));
Scene scene = new Scene(root);
stage.setWidth(500);
stage.setHeight(350);
stage.setResizable(false);
stage.setTitle("My Anagram Game");
stage.setScene(scene);
stage.show();
}
}
why isnt it showing when i run the program??
just for the shizzle, can u go in command and see that fxml file is not placed anywhere else inside your build ?
the image?
or the whole application?
the whole app, nothing appears
any error ?
did you click the run button ?
exit 0 status on console ?
yes
show the full error
click on the first entry of this tree and send us the full error log
> Task :HelloApplication.main()
Jul 31, 2023 3:45:22 PM com.sun.glass.ui.mac.MacApplication lambda$waitForReactivation$6
WARNING: Timeout while waiting for app reactivation
Timeout while waiting for app reactivation
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:1623)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3369)
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3332)
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3300)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3272)
at javafx.fxml@20/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3248)
at javafx.fxml@20/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3241)
at [email protected]/com.example.mygame.HelloApplication.start(HelloApplication.java:23)
at javafx.graphics@20/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at javafx.graphics@20/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
at javafx.graphics@20/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application com.example.mygame.HelloApplication
> Task :HelloApplication.main() FAILED
Execution failed for task ':HelloApplication.main()'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.2.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 5s
4 actionable tasks: 1 executed, 3 up-to-date
Detected code, here are some useful tools:
this?
yeah
at [email protected]/com.example.mygame.HelloApplication.start(HelloApplication.java:23)
whats that line?
are you asking me?
yeah
i have no idea what that means
ahhh
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("/screen.fxml"));
why are you using getClass().getClassLoader().getResource()
instead of getClass().getResource()
saw a thread on stack that said that fixed it for someone
i get the same error either way
wait
different error
again show the full error
Caused by: java.lang.ClassNotFoundException: Screen
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:521)
at javafx.fxml@20/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:933)
... 19 more
pls show us your screen.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Screen">
<children>
<Arc fill="DODGERBLUE" layoutX="260.0" layoutY="164.0" length="270.0" radiusX="100.0" radiusY="100.0" startAngle="45.0" stroke="BLACK" strokeType="INSIDE" type="ROUND" />
</children>
</AnchorPane>
Detected code, here are some useful tools:
its searching for a fx:controller called Screen
hm
shouldnt that fxml be inside the actual project ?
no
what do you even mean? being in resources is the way to go
i did rename the file from "Screen" to "screen"
not the file itself
ik, just thought it was pertinent somehow
you know what a controller is in javafx?
no
now?
you basically make a Java class which handles stuff from your fxml
ok shows marked then
your .fxml file is just a model for the application
how to link it?
using the fx:controller in the fxml file
in that version its linked to Screen but that class doesnt exist and was unintended
what did you name your controller and where did you put it?
everything is the deault thing that is created when you make a javafx project in intellij, i havent made a controller myself i dont believe
then make one or remove the fx:controller argument in the fxml file for now
and try running it

thank you all, yall are lifesavers for someone just getting into java/javafx