Forums Register Login

cannot find symbol

+Pie Number of slices to send: Send

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

+Pie Number of slices to send: Send

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

Second, compile like this...

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

Henry
+Pie Number of slices to send: Send
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.

My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1575 times.
Similar Threads
Packages and Classpath
classpath question in KnB
Classpath
using classpath with javac Problem
Plz help me in solving the problem of JAVAC comand
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:53:01.