I have a problem with nullPointer while i'm trying to modify any element from second Panel in my application. How my application look like: I have 2 Panel, first to loggin and second one with Main Application. Steps in my application:
- Create and show 1 panel
- Provide passwords and loggin to database a/ Success - open new panel and hide this one b/ show error message
- Now i'm trying to modify any element from panel 2 but i cant
Caused by: java.lang.NullPointerException
    at sample.ControllerLoginMenu.openScene(ControllerLoginMenu.java:114)
    at sample.ControllerLoginMenu.login(ControllerLoginMenu.java:41)
    ... 58 more
Here is my code
public class ControllerLoginMenu {
@FXML private Label statusMessage; // second Panel
@FXML private Circle statusCircle; // second Panel
@FXML private Label errorMessageConnection; // First Panel
@FXML private Label errorMessagePassword;   // First Panel
@FXML private TextField loginField;         //First Panel
@FXML private PasswordField passwordField;  //First panel
private String username ;
private String password ;
private final String url = "jdbc:oracle:thin:@google.com:6666:NotExist";
private Stage primaryStage = new Stage();
private Connection con;
private Statement statement;
@FXML private void login(ActionEvent event) throws IOException {
    checkConnection();
    openScene(event);
    // From there is the problem'
    errorMessageConnection.setVisible(true); -- no Error
    statusCircle.setFill(Color.RED); -- Error
}
private void openScene(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
    ((Node) event.getSource()).getScene().getWindow().hide();
    primaryStage.setTitle("Masterdata loading application");
    primaryStage.setScene(new Scene(root, 640, 480));
    primaryStage.show();
}
private boolean checkConnection()   {
    boolean result = false;
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return result;
    }
    try {
        con = DriverManager.getConnection(url, username, password);
        statement = con.createStatement();
        String sql = "SELECT SYSDATE FROM DUAL";
        result  = statement.execute(sql);
    }
    catch (SQLException e)
    {
        passwordField.setText("");
        e.printStackTrace();
        return result;
    }
    return result;
}
private boolean getPasswords()
{
    username = loginField.getText();
    password = passwordField.getText();
    if(username.isEmpty() || password.isEmpty())
        return false;
    else
        return true;
}
@Override // Main Class
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("LoginMenu.fxml"));
    primaryStage.setTitle("Masterdata loading application");
    primaryStage.setScene(new Scene(root, 540, 380));
    primaryStage.show();
}
I other posts i have found that this should solve problem, but it didnt.
Platform.runLater(() ->{
statusCircle.setFill(Color.GREEN);});
 
     
    