Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object Question

 
Tiffany Sun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Margaret Tan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Tiffany Sun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Thanks for the code edit Cindy.)
Do you ever "new" the ShipmentMovement vector?
 
Tiffany Sun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic