File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Passing Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing Objects" Watch "Passing Objects" New topic
Author

Passing Objects

Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Hey guys,
Having a few problems with a java project i'm on, i'm pretty new to java so bear with me.
Basically i've created an array of objects, in this case each object contains relevant customer info.
I'm having problems with passing/referencing this array from other parts of the program. Spent the last few hours trying various different things but not really having any luck.
Cheers in advance
Jamie
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
Jamie
You'll have to be more specific if you want help. Where's your code? What error message are you getting? What do you think the problem is?
Asking questions is a bit of a balancing act - too little info or too much and it's very hard for people to help. But posting a not-too-large amount of source and the "interesting bit" of the error message is pretty standard.
So, write back and let's try and figure it out.

--Tim
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
it basically comes down to being able to pass the array to another seection of the code.
Customer[] cust = new Customer[10];
for (int i = 0; i < 10; i++){
cust[i]=new Customer();
cust[i].create(Location,Price,Type,Rooms,Bedrooms,Parking,Gardens,Also);
}
// ok this is creating 10 dummy customer accounts
//the object that i want to pass the array to is
Score op = new Score();
op.getRating(cust, CustomerRecordNo, PropertyRecordNo);
// and that reads
public void getRating(Customer[] cust, int CustomerRecordNo, int PropertyRecordNo){
String Location=cust[CustomerRecordNo].getLocation;

sorry if the codes a bit of a mess, but has slowly been getting worse as i've been playing.
The main problem is passing and receiving the array to the getRating method in Score and be able to access the customer objects methods
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
Well, that all looks pretty good to me. You've got the array types right for the first argument to getRating. I can't tell about the other parameters because you haven't included their declaration here. Hmm...there must be an error outside these snippets. What error message are you getting? Which line does it point to?
One small note, it looks like you've declared int variables 'CustomerRecordNo' and 'PropertyRecordNo'. Usual Java conventions say you should give class names an initial capital letter (as you did with Customer), but that variables should not have an initial capital (ie, 'customerRecordNo' not 'CustomerRecordNo'. However, this is just a stylistic change, doesn't look like it'll solve our problem.
Cheers,
--Tim
[ May 03, 2004: Message edited by: Tim West ]
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
the error i'm gettin is
Score.java:70: cannot resolve symbol
symbol : variable getLocation
location: class Customer
String Location=cust[CustomerRecordNo].getLocation;
^
1 error

and the getLocation method, which is in the customer class is
public String getLocation(){
return(Location);
}
Uwe Suelter
Greenhorn

Joined: May 03, 2004
Posts: 3
Hi Jamie,
isnt it that you just forgot the put brackets at the end:
String Location=cust[CustomerRecordNo].getLocation();
That should solve your problem.
Have fun
Uwe
[ May 04, 2004: Message edited by: Uwe Suelter ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing Objects
 
Similar Threads
How to save to an object
Help with Arrays and ArrayLists
sending mail to multiple user using Array
Help :) 2d array and graphics :)
Starting with SCJD