0

Im making a button that switches to the next scene in Javafx, ie switching to the next FXML file.

Here is the code:

public void submitorder(ActionEvent actionEvent) throws IOException {
        Customer cust = new Customer();
        cust.setOrder(order);  
        tbl.getCustomers().add(cust); 

        if (tbl.getCustomers().size() == noOfDiners) {
            System.out.println("if statement");
            allcustomers = tbl.getCustomers();
            try{
                System.out.println("This prints");
                Window mainWindow = btnSubmitOrder.getScene().getWindow();                      
                FXMLLoader loader = new FXMLLoader();            
                loader.setLocation(getClass().getResource("paymentScreen.fxml"));    
                Parent root = loader.load();
                System.out.println("test");                    
                PaymentScreenController psc = loader.getController();                    
                psc.dataReceiver(allcustomers);
                mainWindow.getScene().setRoot(root);
            } catch(Exception e){
                System.out.println(e.getMessage());   
            }
        }  
        lvOrder.getItems().clear();  
}

So that first print statement in the try method prints out so it goes into the try method but it still doesnt switch the scene. Ive used this exact code elsewhere in my program and it works so it dont know what im doing wrong.

Ive also tried not using a try method but i just get an error. In this case nothing happens

That if statement is also correct

Any help would be appreciated thanks

harp1814
  • 1,494
  • 3
  • 13
  • 31
  • 1
    "I've also tried not using a try method but I just get an error". Inserting the `try`-`catch` doesn't prevent the error, it just prevents you seeing the [stack trace](https://stackoverflow.com/questions/3988788), which means you can't diagnose what went wrong. Remove the `try`-`catch`, read the stack trace (using the previous link to understand it), and diagnose what is going wrong. – James_D Apr 15 '20 at 12:19
  • [mcve] please .. – kleopatra Apr 15 '20 at 15:25

0 Answers0