• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiler Error: cannot find symbol

 
Ranch Hand
Posts: 46
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Brian LaRue
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoa! That did it, interesting. I would have never guessed to try that, Thanks!
[ February 01, 2006: Message edited by: Brian LaRue ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mamoun Jamous
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Josh Bilger,
Your post was moved to a new topic.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic