• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javac, cannot find symbol

 
Ranch Hand
Posts: 63
IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appends the whole directory structure where I'm actually standing and append it to the '.' current directory?
 
Ranch Hand
Posts: 144
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic