#"Location is required" error in JavaFX despite giving location

1 messages · Page 1 of 1 (latest)

surreal elm
#

I keep getting this error while building a simple JavaFX project. Any ideas on how to fix this?

gentle valveBOT
#

<@&987246487241105418> please have a look, thanks.

gentle valveBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

surreal elm
#
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();



    }
}
blazing lava
surreal elm
blazing lava
#

build folder

surreal elm
#

ahh mb

#

same ss

#

hold on

blazing lava
#

the build folder

#

please show it

#

show what's inside

surreal elm
#

i sent the wrong ss mb

blazing lava
#

in classes

surreal elm
blazing lava
#

show resources

surreal elm
blazing lava
#

try to build again

surreal elm
#

is that the same thing as running the program?

blazing lava
#

no

surreal elm
#

alright how do I build then

#

using gradle btw

blazing lava
#

gradlew clean build

#

or something like that

surreal elm
#

where do i input that

#

im new to build tools

blazing lava
#

command line

#

or find the menu in intellij

#

probably at the right

surreal elm
#

i imagine its this

blazing lava
#

ah yes

#

click on build

surreal elm
#

nothings happening

blazing lava
#

nothing in the console ?

surreal elm
#

let me see

#

oh i got it

#

build successful

blazing lava
#

now show what's in build again

#

in classes and resources

surreal elm
blazing lava
#

delete build

#

and build

surreal elm
#

delete the whole folder?

blazing lava
#

yes

surreal elm
blazing lava
#

did you delete it ?

surreal elm
#

yes

blazing lava
#

because build doesn't really match your file tree

#

try to actually run gradlew clean build

surreal elm
#

where do I go to input that

blazing lava
#

console

#

or the menu at the right

surreal elm
blazing lava
#

yes

#

run gradle clean

#

then run gradle build

surreal elm
blazing lava
surreal elm
#

.idea?

gentle valveBOT
# surreal elm .idea?

Looks like you attempted to use a command? Please note that we only use slash-commands on this server 🙂

Try starting your message with a forward-slash / and Discord should open a popup showing you all available commands.
A command might then look like /foo 👍

blazing lava
surreal elm
blazing lava
#

weird 🤔

surreal elm
#

indeed

#

is it supposed to show screen.fxml?

blazing lava
#

yes

surreal elm
#

hm

blazing lava
#

and rhcp.png isn't supposed to be here

#

since you didn't put it in com

surreal elm
#

it is in com

#

oh

#

nvm

blazing lava
#

can you try to put screen.fxml in com.example.mygame

surreal elm
#

done

blazing lava
#

then clean and build again

surreal elm
#

not there

#

gradle is up to date as well

blazing lava
#

show build.gradle

surreal elm
blazing lava
#

build.gradle

surreal elm
#

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'
}
blazing lava
#

I don't know why it doesn't copy screen.fxml sorry

surreal elm
#

i appreciate the help regardless

blazing lava
#

wait for someone else how knows better about gradle then me I guess

gusty thicket
#

is it normal that he has 2 gradle versions ?

surreal elm
#

that is weird

#

running gradle -v gives me 8.2.1

#

i dont remember installing 8.0.2

hard marsh
#

@surreal elm could it be that the screen.fxml is not inside the resources folder?

surreal elm
#

lets see

hard marsh
#

it looks like its outside

#

liek rhcp is inside

blazing lava
hard marsh
#

yeah

#

it still looks outside

blazing lava
#

👀

surreal elm
#

ill fix it

hard marsh
#

based on rhcp.png

blazing lava
#

but

#

I asked him to move it inside mygame

surreal elm
#

had the exact same issue with rhcp.png not showing

blazing lava
#

and he said it still didn't work

surreal elm
#

i didnt run the program with it inside

gusty thicket
#

resources is marked as resource ? just to be sure

surreal elm
hard marsh
surreal elm
#

ill give it a shot

#

@hard marsh is exactly right

gusty thicket
#

rhcp is in com though, even on the older shots

hard marsh
#

its not?

surreal elm
#

rhcp was inside recources

#

screen.fxml was not

gusty thicket
#

same level as com, sorry

hard marsh
#

yeah

surreal elm
#
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??

gusty thicket
#

just for the shizzle, can u go in command and see that fxml file is not placed anywhere else inside your build ?

hard marsh
#

or the whole application?

surreal elm
#

the whole app, nothing appears

blazing lava
surreal elm
#

no errors, it says build successful

#

but nothing appears

blazing lava
#

did you click the run button ?

gusty thicket
#

exit 0 status on console ?

surreal elm
#

yes

blazing lava
#

did you just build

#

or run ?

surreal elm
#

built and ran

#

nvm i found the issue

#

but i still get "location is required"

hard marsh
#

show the full error

surreal elm
#

looks like its not showing again

hard marsh
#

thats not the full error

#

its just your file explorer

surreal elm
#

yeah ik im getting it

hard marsh
# surreal elm

click on the first entry of this tree and send us the full error log

surreal elm
#
> 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


gentle valveBOT
surreal elm
#

this?

hard marsh
#

yeah

#

whats that line?

surreal elm
#

are you asking me?

hard marsh
#

yeah

surreal elm
#

i have no idea what that means

hard marsh
#

HelloApplication.java:23

#

what is line 23 in that file

#

I mean

surreal elm
#

ahhh

#

Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("/screen.fxml"));

hard marsh
#

why are you using getClass().getClassLoader().getResource()

#

instead of getClass().getResource()

surreal elm
#

saw a thread on stack that said that fixed it for someone

#

i get the same error either way

#

wait

#

different error

hard marsh
#

again show the full error

surreal elm
#

same thing it says for line 23 it seems

hard marsh
#
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

surreal elm
#
<?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>
gentle valveBOT
hard marsh
#

its searching for a fx:controller called Screen

surreal elm
#

hm

hard marsh
#

but you have no controller named Screen

#

also not in that location

gusty thicket
#

shouldnt that fxml be inside the actual project ?

hard marsh
#

no

hard marsh
surreal elm
#

i did rename the file from "Screen" to "screen"

hard marsh
#

not the file itself

surreal elm
#

ik, just thought it was pertinent somehow

hard marsh
#

you know what a controller is in javafx?

surreal elm
#

no

gusty thicket
#

have a look at his resources folder icon

#

yours and mine are

surreal elm
hard marsh
hard marsh
# surreal elm no

you basically make a Java class which handles stuff from your fxml

gusty thicket
#

ok shows marked then

hard marsh
#

your .fxml file is just a model for the application

surreal elm
#

ahh okay

#

so i just need to make a class?

hard marsh
#

yeah

#

and then link it to the fxml file

surreal elm
#

how to link it?

hard marsh
#

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?

surreal elm
#

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

hard marsh
#

then make one or remove the fx:controller argument in the fxml file for now

#

and try running it

surreal elm
#

yay

hard marsh
surreal elm
#

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