aspose file tools*
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
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: 18896
    
  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.

 
 
subject: cannot find symbol