tags:

views:

168

answers:

2

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 should 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;
}
+5  A: 

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.

Andreas_D
I set the password with setStudentPassword() in the AddStudent class. in the AddStudent class my sentence return the correct password but in the MainFrame it doesn't.
Johanna
I think that the Dialog `AddStudent` is spawned from `MainFrame`. Check if you really call `getStudentsPassword()` in `MainFrame` after the Dialog was visible and not before.
Andreas_D
A: 

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.

James B