0

I wanted a window (FXML) to show up when the user clicks the button. Apparently, the problem is very weird. Whenever I click the button, there is a strange exception which I'm unable to resolve. If my called FXML use the existing controller as controller class, then the exception is thrown, else the windows loads properly.

Here is what em doing on button click.

Button Click Action:

@FXML
private void handleSmartSingle(ActionEvent ae) throws IOException {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("Spinner.fxml"));
        final Stage stage = new Stage();
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.setScene(new Scene(root));
        stage.show();
    } catch (Exception e) {
        Logger.getLogger(PeersController.class.getName()).log(Level.SEVERE, null, e);
    }
}

And here is the exception em keeping on getting:

javafx.fxml.LoadException:

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 peers.PeersController.handleSmartSingle(PeersController.java:426)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.control.MenuItem.fire(MenuItem.java:462)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
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 peers.PeersController.initialize(PeersController.java:1117)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 61 more

Anyone having any clue, ur help is very much appreciated. Thank You.

Edit: Exception @ 1117 line

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO

    //Miscellaneous
    inboxPath.setText(sharedDirectory.toString()); //1117
    final Circle clip = new Circle(75, 75, 65); //1118
    userImgView.setClip(clip); //1119 and so on.

    //Getting windows Username
    userField.setText(System.getProperty("user.name"));

    //Search-Field text property listner (Dynamic Search)
    searchField.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (!searchField.getText().isEmpty() && ipList.size() != 0) {
                request = "Search";
                System.out.println(request);
                for (String iplist : ipList) {
                    new Thread(new miniClient(iplist)).start();
                }
            } else if (searchField.getText().isEmpty() && ipList.size() != 0) {
                if (!sfiData.isEmpty()) {
                    sfiData.clear();
                }
            }
        }
    });
}

enter image description here enter image description here

androizer
  • 77
  • 9
  • I am still not sure what do you mean by "FXML use the existing controller as controller class". Can you please show what piece of code is at line 1117 of PeersController ? – ItachiUchiha Apr 06 '16 at 19:45
  • @ItachiUchiha `FXML use the existing controller as controller class` means, that this FXML is child FXML which is using controller of parent FXML (from where em calling it). OP Updated. – androizer Apr 06 '16 at 19:55
  • 1
    I still don't get which exact line of code represents line no 1117. Can you add that line in comment? – ItachiUchiha Apr 06 '16 at 20:09
  • Are you saying you are using the same controller class for both controllers? – James_D Apr 06 '16 at 20:12
  • @ItachiUchiha Sorry, my bad. OP Updated. – androizer Apr 06 '16 at 20:13
  • @James_D Both Parent (Peers.FXML) and child (Spinner.FXML) uses the same controller class (PeersController.java). – androizer Apr 06 '16 at 20:14
  • Why would both the FXML use the same controller class? Are the FXMLs identical? – ItachiUchiha Apr 06 '16 at 20:16
  • 1
    Don't do that. It is too confusing: one set of objects will be initialized in the instance that is created when you load `Peers.fxml` and a different set of objects will be initialized in the instance that is created when you load `Spinner.fxml`. You're getting a null pointer exception because either `inboxPath` or `sharedDirectory` is null in the instance that is created when you load `Spinner.fxml` – James_D Apr 06 '16 at 20:17
  • @James_D I thought the same way out, cuz loading the second fxml most likely to call the initialize again to allocate new memory to variables (imo). So, if i create second controller for that, how would I use the #FXML elements of Spinner.fxml in the parent controller.? – androizer Apr 06 '16 at 20:23
  • 1
    Well, you don't. You shouldn't expose UI elements outside of the controller they are defined in. If you need to communicate between different controllers, see the "Passing parameters JavaFX FXML" link in the duplicate question. – James_D Apr 06 '16 at 20:25
  • @James_D Thanks. Roger that. :D – androizer Apr 06 '16 at 20:26

0 Answers0