Question javafx.fxml.LoadException: unknown path

Discussion in 'Developer Support' started by Serene, May 27, 2016.

  1. Trying to follow the guide here Tutorial - JavaFX for Beginners for setting up a GUI, but I'm running into a Load Exception saying unknown path pointing to
    final Parent root = loader.load(vWestFiremaker.class.getResourceAsStream("practice.fxml"));
    in my practiceGui class and
    Platform.runLater(() -> new practiceGui(this));
    in my main class. Can't seem to figure this out as the getResourceAsStream is finding the practice.fxml file under the same package as the main class (which is where it should be finding it). When running the bot, a white box pops up as if it's trying to load the GUI but then I get the unknown path error. I've looked at a few stackOverflow posts and some say the error could be because I don't have a no arguments constructor in my controller class, but the tut didn't have any in theirs? Help pls am nub

    The whole error output:
    Code (Text):
    1.  
    2. javafx.fxml.LoadException:
    3. unknown path
    4.  
    5.    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    6.    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
    7.    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
    8.    at com.deathizpro.bots.vWestFiremaker.practiceGui.<init>(practiceGui.java:18)
    9.    at com.deathizpro.bots.vWestFiremaker.vWestFiremaker.lambda$onStart$0(vWestFiremaker.java:53)
    10.    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    11.    at java.security.AccessController.doPrivileged(Native Method)
    12.    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    13.    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    14.    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    15.    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    16.    at java.lang.Thread.run(Thread.java:745)
    17. Caused by: java.lang.NullPointerException
    18.    at com.deathizpro.bots.vWestFiremaker.practiceController.initialize(practiceController.java:21)
    19.    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    20.    ... 10 more
    Here is the GUI setup:
    Code (Text):
    1.  
    2. public class practiceGui extends Stage {
    3.  
    4.     public practiceGui(vWestFiremaker script) {
    5.         try {
    6.             FXMLLoader loader = new FXMLLoader();
    7.  
    8.             loader.setController(new practiceController(script, this));
    9.  
    10.             final Parent root = loader.load(vWestFiremaker.class.getResourceAsStream("practice.fxml"));
    11.  
    12.             final Scene scene = new Scene(root);
    13.  
    14.             setTitle("vWestFires");
    15.  
    16.             setScene(scene);
    17.         } catch (IOException e) {
    18.             e.printStackTrace();
    19.         }
    20.  
    21.         show();
    22.     }
    23. }
    The fxml file for the gui that I'm trying to create:
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="UTF-8"?>
    3.  
    4. <?import javafx.scene.control.Button?>
    5. <?import javafx.scene.control.ComboBox?>
    6. <?import javafx.scene.control.Label?>
    7. <?import javafx.scene.layout.AnchorPane?>
    8.  
    9. <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="249.0" prefWidth="389.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
    10.    <children>
    11.       <Button fx:id="startButton" layoutX="150.0" layoutY="155.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="90.0" text="Start" />
    12.       <Label contentDisplay="CENTER" layoutX="92.0" layoutY="77.0" prefHeight="25.0" prefWidth="74.0" text="Log Type:" />
    13.       <ComboBox fx:id="logChoice" layoutX="165.0" layoutY="77.0" prefWidth="150.0" />
    14.    </children>
    15. </AnchorPane>
    16.  
    and how I start it in the main class:
    Code (Text):
    1.  
    2. public void onStart(String... args) {
    3.     Platform.runLater(() -> new practiceGui(this));
    4. }
    5.  
    --- Double Post Merged, May 28, 2016, Original Post Date: May 27, 2016 ---
    Added a bit more info on what exactly is happening.
     
  2. You should be using embeddedUI.

    You can see how you can do that here: Tutorial - Implementing Embeddable UI

    Other than that;

    Code (Text):
    1. // Load the fxml file using RuneMate's Resources class.
    2.         FXMLLoader loader = new FXMLLoader();
    3.  
    4.         // Input your GUI FXML file location here.
    5.         // NOTE: DO NOT FORGET TO ADD IT TO MANIFEST AS A RESOURCE
    6.         Future<InputStream> stream = bot.getPlatform().invokeLater(() -> Resources.getAsStream("com/deathispro/bots/bot/uipath"));
    7.  
    8.         // Set controller and root
    9.         loader.setController(new PracticeController(script, this);
    10.         loader.setRoot(this);
    11.  
    12.         try {
    13.             loader.load(stream.get());
    14.         } catch (IOException | InterruptedException | ExecutionException e) {
    15.             e.printStackTrace();
    16.         }
     
  3. For this line here:
    Code (Text):
    1.         Future<InputStream> stream = bot.getPlatform().invokeLater(() -> Resources.getAsStream("com/deathispro/bots/bot/uipath"));
    What exactly goes at the bot.getPlatform().invokeLater. Is the bot.getPlatform() supposed to be replaced with my main bot class? When I do that I get a "nonstatic method getPlatform() cannot be referenced from a nonstatic method.
    --- Double Post Merged, May 28, 2016, Original Post Date: May 28, 2016 ---
    I've also tried using the EmbeddableUI Tutorial and get the same Unknown Path error.
     
  4. ah sorry forgot about having that part in there.
    You either need to take your main script bot as a parameter or find another way to get your main script bot. I can't remember how but there's another way ^^
    It's easiest to just parse it though. That way your gui can also talk to your bot if needed.
     

Share This Page

Loading...