Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124787

JavaFX Application returning NullPointerException in focusInitial when other Scene is called (Just Sometimes)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7u15
    • javafx
    • Windows, Netbeans

      My application has a Login Scene and a Main View Scene, what is happening is when I do my login and MainView is called SOMETIMES I get this exception:

      java.lang.NullPointerException
          at javafx.scene.Scene.focusInitial(Scene.java:1879)
          at javafx.scene.Scene.access$3600(Scene.java:170)
          at javafx.scene.Scene$ScenePulseListener.focusCleanup(Scene.java:2181)
          at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2221)
          at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
          at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
          at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
          at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
          at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
          at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
          at java.lang.Thread.run(Thread.java:722)

      The curious is it doesn't happening always, just sometimes.

      My Main class:

      public class TargetAppDesktop extends Application {

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

              Scene scene = new Scene(new AnchorPane());

              LoginManager loginManager = new LoginManager(scene);
              loginManager.showLoginScreen();
              primaryStage.setResizable(false);
              primaryStage.setScene(scene);
              primaryStage.show();

              primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                  @Override
                  public void handle(WindowEvent t) {
                      MainViewController.deleteTempFiles();
                      Platform.exit();
                      System.exit(0);
                  }
              });

          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      MY LOGIN MANAGER CLASS:

      public class LoginManager {

          private Scene scene;

          LoginManager(Scene scene) {
              this.scene = scene;
          }

          public void logout() {
              showLoginScreen();
          }

          void showLoginScreen() {
              try {
                  FXMLLoader loader = new FXMLLoader(
                          getClass().getResource("Login.fxml"));
                  // scene.getStylesheets().add(this.getClass().getResource("Login.css").toExternalForm());

                  scene.setRoot((Parent) loader.load());
                  LoginController controller =
                          loader.<LoginController>getController();
                  controller.initManager(this);
              } catch (IOException ex) {
                  Logger.getLogger(LoginManager.class.getName()).log(Level.SEVERE, null, ex);
              }
          }

          void showMainViewScreen(Login loginTargetApp, Login loginGateway, Gateway gateway, File file, ArrayList<Integer> anoList) {

                  try {

                      FXMLLoader loader = new FXMLLoader(getClass().getResource("MainView.fxml"));

                      scene.setRoot((Parent) loader.load());

                      MainViewController controller = loader.<MainViewController>getController();

                      controller.initSessionID(this, scene, loginTargetApp, loginGateway, gateway, file, anoList);

                  } catch (Exception ex) {
                      Logger.getLogger(LoginManager.class.getName()).log(Level.SEVERE, null, ex);
                  }

          }

          void autheticated(Login loginTargetApp, Login loginGateway, Gateway gateway, File file, ArrayList<Integer> anoList) {
              showMainViewScreen(loginTargetApp, loginGateway, gateway, file, anoList);
          }
      }

            psafrata Pavel Ĺ afrata
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: