"java.lang.IllegalStateException: Location is not set" in JavaFX application -


i making application accounting firm using javafx. getting strange error when clicking button have set via fxml.

java.lang.illegalstateexception: location not set. @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2434) @ javafx.fxml.fxmlloader.load(fxmlloader.java:2409) 

here main.java code:

    package tech.faraaz.zoforo;  import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.scene.parent; import javafx.scene.scene; import javafx.stage.stage;  public class main extends application {      @override     public void start(stage stage) throws exception {         parent root = fxmlloader.load(getclass().getresource("gui/splashscreen.fxml"));          scene scene = new scene(root);          stage.settitle("zoforo");         stage.setscene(scene);         stage.show();     }       public static void main(string[] args) {         launch(args);     } } 

here splash screen code:

    <?xml version="1.0" encoding="utf-8"?>  <?import javafx.scene.control.button?> <?import javafx.scene.control.label?> <?import javafx.scene.control.listview?> <?import javafx.scene.control.textfield?> <?import javafx.scene.image.image?> <?import javafx.scene.image.imageview?> <?import javafx.scene.layout.anchorpane?>  <anchorpane maxheight="410.0" maxwidth="410.0" minheight="410.0" minwidth="410.0" prefheight="400.0" prefwidth="401.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tech.faraaz.zoforo.gui.splashscreencontroller">    <children>       <imageview fitheight="150.0" fitwidth="200.0" layoutx="24.0" layouty="23.0" pickonbounds="true" preserveratio="true">          <image>             <image url="@../assets/logo.png" />          </image>       </imageview>       <listview layoutx="24.0" layouty="158.0" prefheight="200.0" prefwidth="200.0" />       <button layoutx="248.0" layouty="172.0" mnemonicparsing="false" onmouseclicked="#openaccountwindow" prefheight="27.0" prefwidth="139.0" text="open account" />       <button layoutx="248.0" layouty="209.0" mnemonicparsing="false" prefheight="27.0" prefwidth="139.0" text="new account" />       <button layoutx="248.0" layouty="313.0" mnemonicparsing="false" prefheight="27.0" prefwidth="139.0" text="scan statement" />       <button layoutx="248.0" layouty="276.0" mnemonicparsing="false" prefheight="27.0" prefwidth="139.0" text="open statement" />       <label layoutx="24.0" layouty="374.0" text="copyright zoforo 2017 | zoforo.com" />       <textfield layoutx="24.0" layouty="122.0" prompttext="search profiles..." />    </children> </anchorpane> 

here code in splashscreencontroller.java. using "event" instead of "actionevent".

    @fxml public void openaccountwindow(event event) throws exception {      try {         fxmlloader loader = new fxmlloader(getclass().getresource("gui/openaccountscreen.fxml"));         parent root = (parent) loader.load();          stage stage = new stage();         stage.setscene(new scene(root));         stage.show();     } catch (exception e) {         e.printstacktrace();     } } 

here code openaccountscreen.java.

    <?xml version="1.0" encoding="utf-8"?>  <?import javafx.scene.control.button?> <?import javafx.scene.control.tablecolumn?> <?import javafx.scene.control.tableview?> <?import javafx.scene.control.textfield?> <?import javafx.scene.image.image?> <?import javafx.scene.image.imageview?> <?import javafx.scene.layout.anchorpane?>   <anchorpane maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="384.0" prefwidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">    <children>       <imageview fitheight="71.0" fitwidth="169.0" layoutx="14.0" layouty="14.0" pickonbounds="true" preserveratio="true">          <image>             <image url="@../assets/logo.png" />          </image>       </imageview>       <tableview layoutx="14.0" layouty="137.0" prefheight="200.0" prefwidth="572.0">         <columns>           <tablecolumn prefwidth="204.0" text="account name" />           <tablecolumn minwidth="0.0" prefwidth="218.0" text="account number" />             <tablecolumn minwidth="8.0" prefwidth="149.0" text="statements" />         </columns>       </tableview>       <button layoutx="480.0" layouty="346.0" mnemonicparsing="false" text="open account" />       <textfield layoutx="14.0" layouty="101.0" prompttext="search accounts..." />    </children> </anchorpane> 

any appreciated. thanks.

in main class, package , class name is:

tech.faraaz.zoforo.main 

in splashscreencontroller is:

tech.faraaz.zoforo.gui.splashscreencontroller 

so these classes in different packages.

yet try resource using same relative location.

in main:

getclass().getresource("gui/splashscreen.fxml") 

in splashscreencontroller:

getclass().getresource("gui/openaccountscreen.fxml") 

so relative location of splashcontroller, openaccountscreen.fxml need in following location found:

tech/faraaz/zoforo/gui/gui/openaccountscreen.fxml 

i bet it's not there...

probably, rather accessing fxml relative current class, should access relative given class (e.g. main) or via absolute references. might prevent confusion.

for example, write:

main.class.getresource("gui/splashscreen.fxml"); main.class.getresource("gui/openaccountscreen.fxml"); 

or:

getclass().getresource("/tech/faraaz/zoforo/gui/splashscreen.fxml") getclass().getresource("/tech/faraaz/zoforo/gui/openaccountscreen.fxml") 

note, debug stuff this, can run:

system.out.println(getclass().getresource("gui/openaccountscreen.fxml")); 

if prints null, know resource not in location expect, can troubleshoot there.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -