Forum Stats

  • 3,854,668 Users
  • 2,264,397 Discussions
  • 7,905,749 Comments

Discussions

FXML loadException

ramOfficial
ramOfficial Member Posts: 1
edited Oct 10, 2016 8:15PM in JavaFX 2.0 and Later

Error:-

javafx.fxml.LoadException:

file:/C:/Users/Ram%20Sundar/Documents/NetBeansProjects/PromaE/dist/run1255715815/PromaE.jar!/promae/Login.fxml

  at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)

  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)

  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)

  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)

  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 promae.Maiin.start(Maiin.java:23)

  at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)

  at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)

  at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

  at java.security.AccessController.doPrivileged(Native Method)

  at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)

  at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException

  at promae.LoginController.initialize(LoginController.java:28)

  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)

  ... 17 more

Code:-

package promae;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.stage.Stage;

/**

*

* @author Ram Sundar

*/

public class Maiin extends Application {

   

   @Override

    public void start(Stage primaryStage) {

     try{

     Parent root=FXMLLoader.load(getClass().getResource("/promae/Login.fxml"));

    

     Scene scene=new Scene(root);

     scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

     primaryStage.setScene(scene);

     primaryStage.setTitle("Login");

     primaryStage.show();   

     }   catch(Exception e){

         e.printStackTrace();

     }

    }

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        launch(args);

    }

   

}

Answers

  • bekwam
    bekwam Member Posts: 6
    edited Sep 9, 2016 5:27PM

    Hi,

    Try moving the .fxml next to the .class file.  With this arrangement, you can use your getResource() call or you can make the path relative (just "Login.fxml").

    Good luck,

    Carl

  • Manius
    Manius Member Posts: 29
    edited Sep 17, 2016 11:51AM

    I can't remember yet if it's a different error, but I feel like I've seen this kind of thing before due to security or permissions problems.  Either not requesting enough permissions, or a setting somewhere. 

  • bouye-JavaNet
    bouye-JavaNet Member Posts: 394 Silver Badge
    edited Sep 19, 2016 10:51PM

    Hi, the error is quite clear if you happen to read the trace : you get a NullPointerException in the controller's initialize() method at line 28.

    Caused by: java.lang.NullPointerException  at promae.LoginController.initialize(LoginController.java:28)

    Probably you are trying to manipulate a variable that should have been injected by the FXMLLoader but is not and thus ends up being null. Either you misspelled the name in either the controller or the FXML or you used the attribute id instead of the attribute fx:id in the FXML.

  • Manius
    Manius Member Posts: 29
    edited Oct 10, 2016 8:15PM

    Sheesh, missed the obvious on that one.  Saw a "similar" looking trace recently and assumed it was the same thing, ah well.

This discussion has been closed.