aspose file tools*
The moose likes Beginning Java and the fly likes Object Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object Question" Watch "Object Question" New topic
Author

Object Question

Tiffany Sun
Greenhorn

Joined: Oct 02, 2001
Posts: 26
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
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

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
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
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
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
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
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

Joined: Mar 16, 2001
Posts: 984

(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
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

Joined: Mar 16, 2001
Posts: 984

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object Question
 
Similar Threads
Help me in BMP Relations
Can some pattern help here?
Problem while One to One Relationship
java interface methods cannot have body?
Before making an association