| Author |
Compiler Error: cannot find symbol
|
Brian LaRue
Ranch Hand
Joined: Feb 01, 2006
Posts: 45
|
|
Hey all, Thanks in advance for your help. I'm a Java newbie and am having trouble compiling this program. Here's what I have so far: 2 Classes: 1. Test.java (main class) 2. Customer.java (instantiable class) Path Variable: C:\Program Files\Java\jdk1.5.0_06\bin Code: **************************************************************** (Customer.java) class Customer { private String customerID; private String firstName; private String lastName; private String address; private String emailAddress; private int age; private boolean hasCollegeEd; private double gradePointAverage; private boolean accidentStatus; private double surcharge; public Customer(String c_id, String f_name, String l_name, String add, String email, int a, boolean col_ed, double gpa, boolean a_status) { customerID = c_id; firstName = f_name; lastName = l_name; address = add; emailAddress = email; age = a; hasCollegeEd = col_ed; gradePointAverage = gpa; accidentStatus = a_status; } public double calculateSurcharge(int a, boolean a_status, boolean c_ed, double gpa) { return surcharge; } public void display() { System.out.println("**** ABC Insurance Co. ****"); System.out.println("Customer ID: " + customerID); System.out.println("Surcharge: %" + surcharge); } } ************************************************************ (Test.java) class Test { public static void main(String[] args) { Customer cust1 = new Customer("235678", "John", "Doe", "1313 Mockingbird Ln", "email address", 20, false, 0.0, true); cust1.calculateSurcharge(20, true, false, 0.0); cust1.display(); } } ********************************************************************** When I go and compile this at the command line: javac *.java (inside of my directory) I receive this error: Test.java:3: cannot find symbol symbol : constructor Customer(java.lang.String, java.lang.String, java.lang.String, java.lan.String, java.lang.String, int, boolean, double, boolean) location class: Customer Customer cust1 = new Customer("1234","John","Doe", "1313 Mockingbird Ln.", "email address", 20, false, 0.0, true); 1 error *********************************************************************** It looks like it's complaining about my constructor method, but I've checked to make sure that the arguments match the parameters in type. I'm lost, my guess is that it has something to do with my path variable. Please help!! Thanks again [ February 01, 2006: Message edited by: Brian LaRue ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
Hi Brian, Welcome to JavaRanch! Sometimes you can get yourself into a state where your .class files come from an older version of your source, but have newer timestamps than the source; the compiler will then look at the old/new class files and not the source code, and you'll get an error like this that doesn't make sense based on the source. Carefully delete every "Customer.class" you can find -- you might have some hiding in strange places, so look carefully -- and then try compiling again.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Brian LaRue
Ranch Hand
Joined: Feb 01, 2006
Posts: 45
|
|
Whoa! That did it, interesting. I would have never guessed to try that, Thanks!  [ February 01, 2006: Message edited by: Brian LaRue ]
|
 |
Mamoun Jamous
Greenhorn
Joined: Jul 01, 2010
Posts: 3
|
|
Hi everybody
Well, I've tried the magical solution you have stated but It didn't work for me.
It's true that I'm new to Java as well, so I know that my problem is a silly one.
My files are located in the following architecture, and they are copied right from a book.
c:\jws\ch01\ts\
there is two files in there, the first is TimeServer.java and the other is TimeServerImpl.java
compiling the first one would produce no problems, but since the second one is an implementation of the first, i get the following error when I try to compile it:
C:\jws\ch01\ts>javac TimeServer.java
C:\jws\ch01\ts>javac TimeServerImpl.java
TimeServerImpl.java:13: cannot find symbol
symbol: class TimeServer
public class TimeServerImpl implements TimeServer {
^
1 error
C:\jws\ch01\ts>
the first file code is:
the second file is:
thanks in advance for taking some time to review this.
|
 |
Mamoun Jamous
Greenhorn
Joined: Jul 01, 2010
Posts: 3
|
|
I've managed to compile the file, and here is how:
1. I deleted the compiled file of the first file "TimeServer.class"
2. I closed the prompt window and opened a new one and typed:
c:\> javac jws/ch01/ts/*.java
I have no idea why it worked this way, but it does.
I would feel very happy to hear an explanation
wish you all a nice day.
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
You need to compile your code from C:\jws - and then use the package in front of the Class name
Like this:
C:\jws>javac ch01/ts/TimeServer.java
C:\jws>javac ch01/ts/TimeServerImpl.java
and then when you want to call the Class, do it from the same folder - and again starting with package.
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Mamoun Jamous
Greenhorn
Joined: Jul 01, 2010
Posts: 3
|
|
I've tried to do what you have mentioned, but it didn't work!
I've tried to compile a new file named TimeServerPublisher.java, which is located at the same folder
I tried:
c:\jws> javac ch01/ts/TimeServerPublisher.java
the error message I had is exactly the same.
I deleted all .class files, then tried again the following:
c:\javac jws/ch01/ts/*.java
and it worked perfectly for the 3 files.
is it possible that I have to compile all the files from the same location "like i've done it from c:\ for the first two yesterday, so i have to do it from the same location today for the 3rd file"? I'll try and comment later.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Josh Bilger, Your post was moved to a new topic.
|
 |
 |
|
|
subject: Compiler Error: cannot find symbol
|
|
|