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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Symbol trouble" Watch "Symbol trouble" New topic
Author

Symbol trouble

Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
As a beginner at Java I know enough to know I have done something wrong but not enough to know how ot fix it.

Car = new Car(reg, make, model, colour, passenger_no);

Is getting the errors

File: C:\Documents and Settings\Lari\My Documents\Huddersfield\Programming\Coursework2\Vehicles.java [line: 67]
Error: cannot find symbol
symbol : variable Car
location: class Vehicles
File: C:\Documents and Settings\Lari\My Documents\Huddersfield\Programming\Coursework2\Vehicles.java [line: 67]
Error: cannot find symbol
symbol : variable passenger_no
location: class Vehicles

I have got another class called Car.java, which starts with public class Car {

Is there some reason Java can't find this class?

Any help would e gratefully received as I seem to have been battling all day with this.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
If Car is the type, then you also have to name the reference:

Car myCar = new Car(...);


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
I see, thanks for that, I have now changed the code to:

Car car = new Car(reg, make, model, colour, passenger_no);
carList.add(car);

The only other problem with this bit I think (and hope) is

Error: cannot find symbol
symbol : variable passenger_no
location: class Vehicles

I have declared passenger_no in my Car.java file as follows:

private int passenger_no;

does this code need something else?
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
Looking again it is the int variables that it can't find. Can you group int values with strings?
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
Any help would be much appreciated, I can't work out what else could need changing, and one of the symbols not found is a String...

(Vehicles.Java)
Service service = new Service(service_no, reg, date, miles, part_replaced);
serviceList.add(service);
-------------------------------------
(Service.Java)
private int service_no;
private String reg;
private String date;
private String miles;
private String part_replaced;

public Service(int servNo, String reg, String dat, String mil, String part)
{
service_no = servNo;
reg = reg;
date = dat;
miles = mil;
part_replaced = part;
--------------------------------------------
(Error)
Error: cannot find symbol
symbol : variable part_replaced
location: class Vehicles

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

There is the variable you pass TO a method, the variable you call it IN the method, and in your case, a member variable called the same thing (i think).

You have your Service.java class. This says that all Service objects will have (among other things) a String part_replaced.

you have a constructor for the Service class, that takes in (among other things) a String part.

in your Vehicles.java, you call the constructor for making a new service. you pass into that constructor (among other things) a part_replaced.

does the compiler tell you which line it can't find the variable? I'm guessing it's the line in Vehicles.java. do you have that variable defined in there?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Service service = new Service(service_no, reg, date, miles, part_replaced);


Have you declared these variables in your Service class?
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122

1. Please take a look if the variable "part_replaced" is defined in class Vehicles... perhaps you defined "part" instead?
2. The "reg=reg" in your constructor isn't the best idea. It should be "this.reg=reg", because else you will not change the "content" of your member variable.


Please check if you declared passenger_no in your Vehicles class, too. Perhaps you just forgot?
Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51
Still new to java here too. But question if it is being declared as private, I thought it would intially error as symbol not found being called from another class. If it is - private int passenger_no; wouldn't it have to be declared as a different variable for other classes to access it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Symbol trouble