Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date becomes null b/w mehod calls

Status
Not open for further replies.

pgk

Programmer
Jul 19, 2002
262
0
0
US
Hi,
I have a class with a java.util.Date object as part of it. I pass an object of this class to another which in turn sends it to another acouple of methods and finally sets the date field.

After the control returns to my original method, I am able to access the date value set by the other method. But when I pass this class object to another method, the date field has a value of null.

I overcame this problem by capturing the date in a local variable after it returns from the call to the first method. Then I set it back and it worked fine.

Pseudocode:

method1()
{
method2(myClass);
// Follwoing line prints date correctly as set by method2
System.out.print(myClass.getDate());
tempDate = myClass.getDate();
myClass.setDate(tempDate);
method3(myClass);
}

method2(myClassPassedByMethod1)
{
myClassPassedByMethod1.setDate(dateVariable);
}

method3(myClassObjectPassedByMethod1)
{
System.out.print(myClassObjectPassedByMethod1.getDate());
}


the pseudocode when implemeted works finw. But if you remove the reassignment in method1, the date is null in method3.

Any help would be very much appreciated and sorry for the long post. Thanks in advance.

Hope it helps. Let me know what happens.
With regards,
PGK
 
I just tested your code and it works fine for me WITHOUT the reassignment. Can you post your complete code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top