In my login class I get the users name. Then in my report class I try to retrieve that name. I have used breakpoints when I enter the users name in login the string appears correct. However, when I try to access it from the report class the function from login then returns a null string. I have looked around on stack and used google and am pretty sure I am following what I am supposed to do but it is not working.
Here is some code from login. I can show more code if needed, but when I use breakpoints in login, the dName is always the correct name, and so is driversName. But when I come back to returnName from report, driversName is then a null string. I have declared driversName as a global and not local variable in my class.
private void getDriversName(String dName)
{
driversName=dName;
}
public String returnName()
{
return driversName;
}
Here is the code from report. Once again I can add more id needed. Also I imported login correctly. I used breakpoints and when I used the step in, it took me to login. name is coming back null.
LogIn login;
login=new LogIn();
String name= login.returnName();
driver.setText(name);
UPDATE: I figured it out I needed to add static.
Are you calling getDriversName function before calling login.returnName(); as from your code it is visible that driversName will have value right after getDriversName function call.
Further you can implement other approach for login and other tasks i.e. keep a common class which maintains all such sessions. You can set values once you login and then get them any where in your whole project. Like
and call this function after login success.
Hope this will help.