After I defined an object, can I change part of it? 1 Shipment shipment = new Shipment(); 2 shipment = someFunction(); 3 shipment.AddVector(anVector); Why does the third line always been ignored? How can I fix this?? Thanks. Tiffany
SCJP, SCWCD, IBM-XML
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Tiffany Your second line is setting the shipment variable to refer to a different Shipment object other than the one you created in the 1st line. So in your third line the AddVector method is doing whatever it does to the new Shipment object, could this be your problem? If not post some more code, like what does the AddVector method do and where does the anVector variable come from.
------------------ Dave Sun Certified Programmer for the Java� 2 Platform
Dave
Margaret Tan
Greenhorn
Joined: Sep 14, 2001
Posts: 20
posted
0
I don't understand. How can someFunction() here becomes an object? It was not created using the new keyword.
jason adam
Chicken Farmer ()
Ranch Hand
Joined: May 08, 2001
Posts: 1932
posted
0
But if someFunction() returns an object of type Shipment, then your putting that returned object with the shipment reference. You don't always use the new keyword to associate a reference with an object. Jason
Michael Bruesch
Ranch Hand
Joined: Sep 23, 2001
Posts: 158
posted
0
I think more code posted is in order to correctly answer this question. ------------------ Michael J Bruesch Codito, ergo sum... I code, therefore I am. [url = http://www.geocities.com/mjbruesch/games]My Java Games, I'm quite proud[/url]
Michael J Bruesch<br /><i>I code, therefore I am.</i>
Tiffany Sun
Greenhorn
Joined: Oct 02, 2001
Posts: 26
posted
0
Yes someFunction returns a Shipment object. If I change to this: Shipment shipment = someFunction(); shipment.addVec(aVector); Do you think this will work? Thanks. Tiffany
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Tiffany We really need to see a bit more code. Ther eis nothing wrong with the code you've posted so far. If something is not working the way you expect it to post the relevant code so we can see what it is you're doing.
------------------ Dave Sun Certified Programmer for the Java� 2 Platform
Tiffany Sun
Greenhorn
Joined: Oct 02, 2001
Posts: 26
posted
0
Hi Dave: Here's what I'm trying to do:
In JSP: ShipDesignAccessBean aship=new ShipDesignAccessBean(); aship.anotherFunction(aLoadNum); I never got the movement vector, but I did get the beginPoint and endPoint... Tiffany (edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited October 25, 2001).]
(Thanks for the code edit Cindy.) Do you ever "new" the ShipmentMovement vector?
Please ignore post, I have no idea what I am talking about.
Tiffany Sun
Greenhorn
Joined: Oct 02, 2001
Posts: 26
posted
0
Thanks Cindy. The Vector works fine. if I try Shipment shipment=new Shipment(); shipment.addVec(aMove); I can get the movement in JSP, but by adding another line in the middle(shipment=anotherFunction()), the last line is ignored. I also tried this: Shipment shipment=anotherFunction(); shipment.addVec(aMove); It didn't work either. Could anyone help me with this? Thanks. Tiffany
In the general sense what you are trying to do should work. So you need to start troubleshooting. Try putting a print in the method that you call to load data into the vector (setVector, addVec, whatever you are calling it). This will let you know if and when the method is being called and what values are being passed to it. Having this information should allow you get closer to figuing out what the problem is.