• 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

cannot find symbol error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on the Web Component Developer Exam and trying to work out a simple example for usage within JSP

I'm trying to create an abstract class Person and a Employee class that extends Person

Both java-files in the same package and I'm also creating the classes there. How simple can it be?
But either my java got very rusty or java is just too dumb

The person class is created, but the employee is not.
I got the error

Employee.java:23: cannot find symbol
symbol: class Person
public class Employee extends Person {

To my knowledge it's not even needed because they are in the same package (and directory)
but even when I use -classpath directory it fails to compile
When I remove the extends clause from Employee.java it compiles.

Very discouraging that even the simplest of the simplest goes wrong.
java version is 1.6.0_11

Here are the classes:

Person:

package foo;

public abstract class Person {
private String name;

/* public Person() {
name = "Initial value";
}*/

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

}

Employee class

package foo;

import foo.*;

public class Employee extends Person {
private int empID;

public Employee() {
empID = -1;
}

public int getEmpID() {
return this.empID;
}

public void setEmpID(int id) {
this.empID = id;
}

}






 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you are attempting to compile from a command line? If so, please post the command you used. Also please use code tags when you post. I suspect you have a classpath issue.
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
compile first Person class as

after that compile Employee class as
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your classpath is wrong.

Also, please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button. Thanks!
 
remco Brand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your quick answers:

In answer to Tom:

Yes I tried it from the command line.I'm using Windows XP

The classes and java-files are in
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo

Documentation from Sun (http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html)
states that when you don't specifiy classpath it looks in the current directory

That didn't work, the documentation doesn't seem correct?
So I gave the full classpath (the directory where I'm currently standing in by the way)

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo" Employee.java

Same error

I tried it with

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo\" Employee.java

it gave me the following error/message

javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options

I tried it with
javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo";. Employee.java

(this should add the current directory to the classpath, isn't it?)
Same result

As for the suggestion of Pramod

When I first do

javac -d . Employee.java
(with Person.class and Person.java already present in the directory)
it gives me the same error

But indeed when I first do

javac -d . Person.java

and then

javac -d . Employee.java

it compiles!
This behavoir really puzzles me.

Getting these simple classes to compile did cost me about 3 hours of valuable preparation time for the exam
I have found the behavoir of the javac compile command also in past experiences very user-unfriendly and often very different from what I would expect. But I guess I'm the only one here....












 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless you're using Java 1.3, don't use Java 1.3 documentation.
 
remco Brand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, ok, ok, here you go:

http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html

As you would expect the behavoir stayed the same according to the documentation. if not specified, it looks in the current directory.
At least according to the documentation.

In the mean-time I found that

the command

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\" Employee.java

also compiles the class. So the classpath apperantly has to be given to the root of the package-structure
I still find it silly and counter-intuitive that the java-compiler doesn't look in the current directory for the classes


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your original example the source file was in your current directory, but was in package foo. If you had just gone up a single level and used "." as the classpath (plus whatever else you need) it would have worked fine. Now it looks like you're using deployed classes, which is fine, but somewhat over-complicating things.
 
remco Brand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand now a bit better how the compiler thinks/work
in this case
java -cp .. Employee.java also works
and then going one directory higher
java foo\Employee.java also does the trick.

And I still think the way java and class files are handled by the compiler is somewhat inconsistent

When I go one directory and type

javac foo.Employee.java
it gives me an error that the file is not found
But the compiler does look for the class foo.person from this place

I still find it counter-intuitive that the java-compiler doesn't look in the current directory (C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo) for the classes it needs
But I guess I have to come to terms with this behavoir

I didn't understand what you mean with deployed classes?




 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

remco Brand wrote:I still find it counter-intuitive that the java-compiler doesn't look in the current directory (C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes\foo) for the classes it needs


But Java uses a hierarchical package structure, and you've defined the class to be in package "foo"--that's just the way it is.

Are you keeping your source files in the Tomcat distribution directory?!
 
remco Brand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't use the distribution
Just the old handwork

Thanks for your answers.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't actually answer my question--right now it looks like you're keeping your source files in the Tomcat distribution directory.

Where are your source files located?
 
reply
    Bookmark Topic Watch Topic
  • New Topic