I'm getting an error when I create static methods and call them in another class:
public static JTextField getNameTxtField(){
return nameTxtField;
}
public static JTextField getNewUserNameTxtField(){
return newUserNameTxtField;
}
public static JPasswordField getNewPasswordTextField(){
return newPasswordTxtField;
}
All the above getters are located in the MainForm
class and are called in the this class:
GameLogic
:
public void addToDatabase() throws SQLException {
controller.addUserToDatabase(MainForm.getNameTxtField().getText(),MainForm.getNewUserNameTxtField().getText(), String.valueOf(MainForm.getNewPasswordTextField()) , "insert into application_user values(?, ?, ?)");
}
Why am I getting the message? I don't really understand the message so can someone explain to me?
I can't create an object like this: MainForm form = new MainForm();
in the class GameLogic
because I will get a StackOverflowError
.
Does the problem occur because I call the static getters in a non-static method?