开发者

why it returns null?

开发者 https://www.devze.com 2022-12-12 17:00 出处:网络
I have 3 classes that I have written some part of them below.when i write`this statement in AddStudent class ,it will show abcd1234 which is the password, but when I write it in the MainFrame class it

I have 3 classes that I have written some part of them below.when i write`this statement in AddStudent class ,it will show abcd1234 which is the password, but when I write it in the MainFrame class it will return null.why??? (I send my management object from MainFrame to the AddStudent with AddStudent's constructor) (I need the management object's information which is created in the AddStudent class in the mainframe ) what shoul开发者_如何转开发d I do?

management.getStudentsPassword();

my AddStudent class:

public class AddStudent extends javax.swing.JDialog {

private SystemManagement management;


/** Creates new form AddStudent */
public AddStudent(java.awt.Frame parent, boolean modal, SystemManagement management) {
    super(parent, modal);
    initComponents();
    this.management = management;

}

my MainFrame class:

public class MainFrame extends javax.swing.JFrame {

/** Creates new form MainFrame */
private SystemManagement management;
.
.
.}

my SystemManagement class:

private String studentsPass;
...
public void setStudentspassword(String password){
studentsPass = password;
}
public String getStudentsPassword(){
return studentsPass;
}


Reason one - password has not been set, when you call getStudentsPass() in MainFrame.

Reason two - The SystemManagement object you use in MainFrame and the one you get in AddStudent are simply not the same.

Hard to tell without more code. But I favour Reason one - check the program flow, when is the password set, when do you try to get it.


It's not clear from your question where setStudentPassword is being called from, it can't be being called if it is still leaving studentsPass null.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号