Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol

 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Second, compile like this...

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

Henry
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic