• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javac, cannot find symbol  RSS feed

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

*aaah* I'm failing at such a simple theme. I want to compile B.java



They're in the same package xyz\scjp\chapter10\test\xcom

I'm standing in the xcom directory and calling javac -classpath . B.java
and getting:
B.java:9: cannot find symbol
symbol: class A
public class B extends A


But why?

edit:
And even funnier, the solution of the book javac -classpath . xcom\B.java standing in the directory test doesn't work too...
 
Tim Moores
Saloon Keeper
Posts: 4024
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath "." means that it starts in the current directory - in the xcom directory. So it's looking in xcom\xyz\scjp\chapter10\test\xcom - which doesn't exist. Two ways to proceed: a) go to the top of the classpath hierarchy (the directory above "xyz") and issue javac -classpath . xyz\scjp\chapter10\test\xcom\B.java (BTW: "-classpath" can be shortened to "-cp") or b) compile all classes in one go: javac -cp . *.java
 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appends the whole directory structure where I'm actually standing and append it to the '.' current directory?
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default class path is the current directory and using -classpath option command line option overrrides that default. Take class path option out and use javac B.java as you are already in that directory.

Hope this helps.
 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately no, it's still not clear to me. Ok, if I write -classpath . or leave it away is the same. And causing the same error from posting #1.
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok Java error is B.java:9: cannot find symbol

can you please post your code from class A & B. Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Samson wrote:
They're in the same package xyz\scjp\chapter10\test\xcom


You have to distinguish between "package" and "directory". They are not the same thing. A package will put the class in a particular directory. A class in a directory does *not* always mean that it is in that package.

So, when you say they are in the same package, do you mean in the same directory? Please also show us the code that defines package.

Henry

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are in the same package --> xyz.scjp.chapter10.test.xcom and in the same directory D:\path\to\project\xyz\scjp\chapter10\test\xcom

The code of the classes is in the first posting. They have no content. B extends A, that's the only thing.

edit:
Ah, I've got it. The problem is that if I'm standing in the lowest package 'xcom' where the .java files are and try to perform javac B.java it appends the package declaration of A.java to the current directory. Like Tim Moores said it in the second post... At last the penny's dropped!

Thanks to all.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try searching the forums for the word "xcom". Many people before you have asked the same question; you'll find some useful answers.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are still early enough in your career to post in “beginning”, you might do better to omit the package names from your code and use the unnamed package.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!