0

Basically my question is if I am making a opening a new window from a different fxml file, do I need to initiate it on the FX thread by calling Platform.runlater

Private Chat Class- this is created by a call to a mediator that opens the private chat window by creating a new private chat class object.

public PrivateChatFrame(final Mediator mediator, final User user, final ImageLoader imageLoader,
                        final Settings settings,
                        final ErrorHandler errorHandler) {
    Validate.notNull(mediator, "Mediator can not be null");
    Validate.notNull(user, "User can not be null");
    Validate.notNull(imageLoader, "Image loader can not be null");
    Validate.notNull(settings, "Settings can not be null");
    //Validate.notNull(swingMessages, "Swing messages can not be null");
    Validate.notNull(errorHandler, "Error handler can not be null");

    try {

        newPrivStage = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/net/usikkert/kouchat/ui/swing/ChatRoom.fxml"));
        Parent root = loader.load();
        newPrivStage.setTitle("Flake");
        newPrivStage.setScene(new Scene(root, 416, 498));
        this.chatRoomController = loader.getController();
        System.out.println("Private Chat Frame Made");
        newPrivStage.show();

        newPrivStage.setOnCloseRequest(new EventHandler<javafx.stage.WindowEvent>() {
            @Override
            public void handle(javafx.stage.WindowEvent e) {
                newPrivStage.hide();

            }
        });

    }
    catch(Exception e){
        System.out.println("Catch");
        e.printStackTrace();
    }

    msgTF = chatRoomController.getMessageArea();

    this.mediator = mediator;
    this.user = user;
    messageList = chatRoomController.getMessageList();
    messageList.setItems(messages);
    statusIcons = new StatusIcons(imageLoader);
    me = settings.getMe();
    user.setPrivchat(this);
    isVisible = false;

    //updateUserInformation();

    final FileTransferHandler fileTransferHandler = new FileTransferHandler(this);
    fileTransferHandler.setMediator(mediator);


    cmdHistory = new CommandHistory();
} 

The method that creates the private chat method

@Override
    public void createPrivChat(final User user) {

        if (user.getPrivchat() == null) {

                    user.setPrivchat(new PrivateChatFrame(SwingMediator.this, user, imageLoader,
                                                          settings,  errorHandler));
                }


        if (user.getPrivateChatLogger() == null) {
            user.setPrivateChatLogger(new ChatLogger(user.getNick(), settings, errorHandler));
        }
    }

This is the error message I get. Do i need to do a Platform.runLaterwhen i initiate the window? I thought since the window is like a seperate instance from the already initiated fxml window they wouldn't be on the same thread

Mar 30, 2018 1:57:07 PM net.usikkert.kouchat.util.UncaughtExceptionLogger uncaughtException
SEVERE: UncaughtException in thread: JavaFX Application Thread (id 15, priority 5)
java.lang.NullPointerException
    at net.usikkert.kouchat.ui.swing.PrivateChatFrame.<init>(PrivateChatFrame.java:129)
    at net.usikkert.kouchat.ui.swing.SwingMediator.createPrivChat(SwingMediator.java:830)
    at net.usikkert.kouchat.ui.swing.SwingMediator.showPrivChat(SwingMediator.java:848)
    at net.usikkert.kouchat.ui.swing.SidePanel.lambda$null$0(SidePanel.java:168)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
forests
  • 143
  • 3
  • 9
  • What is on line `129` inside `PrivateChatFrame.java`? – Eng.Fouad Mar 30 '18 at 22:42
  • @Eng.Fouad it is `messageList.setItems(messages);` its how i assign my observable list to my listview – forests Mar 30 '18 at 22:46
  • Then it seems that `chatRoomController.getMessageList();` returns `null`. – Eng.Fouad Mar 30 '18 at 22:52
  • @Eng.Fouad can I just get my controller like that. I have it assigned in the fxml file and assumed its automatically created and thus i can get the specific fxml components i need though getters from the controller – forests Mar 30 '18 at 22:54
  • Wait i see my mistake. I forgot to name my components in my fxml file LOL. Thanks for the help – forests Mar 30 '18 at 23:00

0 Answers0