This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes cannot find symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "cannot find symbol" Watch "cannot find symbol" New topic
Author

cannot find symbol

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324

Directory Structure: foo/test/xcom/x1com/x2com
B.java is in xcom and A.class is in x2com

foo
test
xcom
B.java
x1com
x2com
A.class



I am trying to compile classB, but could not find A.class

Following are my failed attempts in Windows

C:\javac\foo\test\xcom\x1com>javac -classpath . C:\javac\foo\test\xcom\B.java
C:\javac\foo\test\xcom\B.java:2: cannot find symbol
symbol: class A
public class B extends A{}
^
1 error

C:\javac\foo\test\xcom\x1com\x2com>javac -classpath . C:\javac\foo\test\xcom\B.java
C:\javac\foo\test\xcom\B.java:2: cannot find symbol
symbol: class A
public class B extends A{}
^
1 error


C:\javac\foo\test>javac -classpath . C:\javac\foo\test\xcom\B.java
C:\javac\foo\test\xcom\B.java:2: cannot find symbol
symbol: class A
public class B extends A{}
^
1 error

C:\javac\foo\test>javac C:\javac\foo\test\xcom\B.java
C:\javac\foo\test\xcom\B.java:2: cannot find symbol
symbol: class A
public class B extends A{}
^
1 error


C:\javac\foo\test>javac -classpath .;C:\javac\foo\test C:\javac\foo\test\xcom\B.java
C:\javac\foo\test\xcom\B.java:2: cannot find symbol
symbol: class A
public class B extends A{}
^
1 error


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40


First, in class B, you need to import A.

Second, compile like this...

C:\javac\foo\test>javac -classpath . xcom\B.java

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Basically I forgot to import it.

Just to add..even the following statement will work.

C:\javac\foo\test>javac xcom\B.java

So I understand, while searching .class file javac will search by appending the package structure from the current directory (here it appends xcom\x1com\x2com), but to search for .java files it has to put the path explicitly while searching.

Thanks Henry.

 
Consider Paul's rocket mass heater.
 
subject: cannot find symbol
 
Similar Threads
using classpath with javac Problem
Classpath
Packages and Classpath
Plz help me in solving the problem of JAVAC comand
classpath question in KnB