I am getting object from TextField and PasswordField, but I need to use it as a String in my class. I have variables set like this, but the application is crashing
@FXML private TextField email;
@FXML private PasswordField password;
private String stringPassword = password.getText();
private String stringEmail = email.getText();
Edit: I put the getText to the relevant method, with no success. Now I have
@FXML public void logIn() throws IOException
{
String p = password.getText();
String e = email.getText();
System.out.println(p);}
All this leading to NullPointerException
you must not call this
password.getText();andemail.getText();in that place. becauseTextFieldandPasswordFieldare not initialized yet. So you should call them in a method in your class.