0
public class Screen1DocumentController implements Initializable {

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    

    @FXML public void handleLogin() throws IOException{
        Parent root = FXMLLoader.load(getClass().getResource("Screen2Document.fxml"));
        Scene scene = new Scene(root);

        Stage stage = new Stage();
        stage.setScene(scene);
        stage.show();
    }

    @FXML Button btnLogin;


}

Below Screen2DocumentController.java:

public class Screen2DocumentController implements Initializable {

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        ReportDetails r;
        r = new ReportDetails("pavan");
        rptDtls.add(r);
        rptDtls.add(new ReportDetails("Viajy"));
        rptDtls.add(new ReportDetails("sharat"));
        rptDtls.add(new ReportDetails("sandeep"));
        rptDtls.add(new ReportDetails("bhaskar"));
        rptDtls.add(new ReportDetails("nokal"));

    }    

    private ObservableList<ReportDetails> rptDtls =  FXCollections.observableArrayList();
    @FXML TableView tblData;
    @FXML TableColumn<ReportDetails,String> tblCData;
}

When I click on the login button I am getting run time errors. What am I doing wrong?

embedded.kyle
  • 10,976
  • 5
  • 37
  • 56
pavankumar
  • 25
  • 1
  • 9

2 Answers2

0

First put your FXMLLoader call into a try/catch to get detailled information about the error.I guess that your path to Screen2Document.fxml is not correct or the import statement for ReportDetails is missing?

Inge
  • 427
  • 7
  • 20
  • now i am able to send data from Screen1DocumentController to Screen2DocumentController i read this post "http://stackoverflow.com/questions/12166786/multiple-fxml-with-controllers-share-object/" this is fine for sending data from controller1 to subcontroller.But i want data to be sent from subcontroller to controller1.? – pavankumar Mar 07 '14 at 13:14
0

You could pass a reference of controller1 to controller2 by

    Screen2DocumentController controller2 = (Screen2DocumentController)fxmlloader.getController();

add variable to Screen2DocumentController

private Screen1DocumentController controller1;

add a method to Screen2DocumentController

public void setScreen1DocumentController(Screen1DocumentController controller){this.contoller1 = controller; }

now you can call method in your handlelogin method

((Screen2DocumentController)fxmlloader.getController()).setScreen1DocumentController(this);

now you have a reference of controller1 in controller2.

If you now add a method to Screen1DocumentController sayHello

public void sayHello(String name){ System.out.println("Hello "+name);}

you could call it from Screen2DocumentController by using

controller1.sayHello("pavankumar");

Hope that helps

Inge
  • 427
  • 7
  • 20