Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application Design a Better App Resources

Federico Chin
Federico Chin
8,765 Points

I just moved my sample.fxml file to the resources/fxml directory and program no longer runs.

I followed the instructions and my program no longer runs. This is the message I am getting:

"C:\Program Files\Java\jdk1.8.0_60\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.4\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_60\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext\zipfs.jar;C:\Users\Federico\IdeaProjects\Sup\out\production\Sup;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain sample.Main Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException: Location is required. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097) at sample.Main.start(Main.java:13) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191) ... 1 more

Process finished with exit code 1

Thank you in advance

6 Answers

Federico Chin
Federico Chin
8,765 Points

I just fixed it. I thought I followed all the instructions. I did not remove the "resource" directory from the absolute path, therefore, my code was not executing. It is very important to set the absolute path to:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        //Very important to remove the "resource" directory name
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));



        primaryStage.setTitle("SUP");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }
Craig Dennis
Craig Dennis
Treehouse Teacher

Glad you got it sorted Federico! Thanks for sharing the fix!

raul cortes
raul cortes
5,745 Points

I still dont get it, if the initial route was ok, why is not working(I know its been a year but i started this track like 2 weeks ago). Is the getResource() method what is giving me the route?

Wolf <null>
Wolf <null>
5,060 Points

I have the same problem and can't get it to work. Had to copy the the sample.fxml file and paste it into resources/fxml 'cause otherwise IntelliJ frooze up. Deleted the sample.fxml file under src/sample and refactored.

Hey all, my main.java matches Federico's exactly, but the .getResource() method is still throwing a null pointer exception. I suspect that there is an issue with the intellij idea in Sup.iml since it never asked me to search and refactor when I moved the FXML file to resources. Does anyone see a difference between my current idea and theirs?

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
Jose Aguirre
Jose Aguirre
14,866 Points

I did the exact same thing, hah.

Michael Ball
PLUS
Michael Ball
Courses Plus Student 3,582 Points

I am also having a similar issue to Federico Chin and it is making me go crazy, especially since I have gotten it to work once. But only once! I need help with this. I have tried all the suggestions above me and I am still having issues. Please, can the treehouse community help me solve this problem. I would really love to get a crack at JavaFX.

Michael Macdonald
Michael Macdonald
34,265 Points

I had this same issue. I moved the file and typed exactly the same as Craig had done.... And it still didn't work :((( THEN, I watched the video again......AND I realised that I had forgot to mark the newly created resource directory as the 'Resource Root'. Right-click on your new created 'resources folder', Then scroll down to 'Mark Directory as', Then select 'Resources Root'. Not sure if this will help, but it help me :))))