• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot Find Symbol, Interfaces  RSS feed

 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three classes that look like:



And i keep getting the errors on the "PortfolioStatisticsCalculator"



Any ideas why???
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling using the classpath flag with the current directory (denoted by a dot)...

javac -cp . PortfolioStatisticsCalculator.java

(Assuming that your current directory is statistics.) If this works, then you're getting the error because you have a system classpath set, and it does not include the dot for the current directory.
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey marc thanks for the reply. I tried what you said, but i am still recieving the same error. Any other ideas what may be causing the problem?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I believe he meant "assuming your current directory is Desktop. You can't compile from down there in the directory where the files are -- well, you can, but only if you really know what you're doing. Try

C:\Documents and Settings\Owner\Desktop> javac -classpath . com\xco\portfolio\statistics\PortfolioStatisticsCalculator.java
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked perfectly, but why wont it work if i try to do it in the statistics directory?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Actually I believe he meant "assuming your current directory is Desktop. You can't compile from down there in the directory where the files are -- well, you can, but only if you really know what you're doing...

Thanks, Ernest!

But actually, I did mean "down there in the directory where the files are." This works for me. What am I missing?
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thats when i try to compile from "down there". I dont know why it doesnt work, but im keen to find out
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When looking for class files or source files to compile -- files not named explicitly on the command line -- javac will look along the classpath for the "roots" of package hierarchies. If it wants to find com.xco.portfolio.statistics.Portfolio, it's going to be looking for a "com" directory. The classpath should specify where that "com" directory is. So to use "-classpath .", "com" needs to be in the current directory. You could do something like "javac -classpath ../../../.. PortfolioStatisticsCalculator.java" from down in the statistics directory, and that should work OK.

But I can't explain why it works for marc. Maybe on reflection he can figure out what's going on there himself.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stephen Foy:
...im keen to find out

Me too. I'm using a Mac, so this looks a little different, but it works for me (and I'm not doing anything clever that I know of)...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
...I can't explain why it works for marc. Maybe on reflection he can figure out what's going on there himself.

Okay, I've reproduced Stephen's error messages (by doing it the... uh, right way).

But now I need to understand why it worked the way I did it. Let's say (hypothetically) that I were to cheat, and put all 3 class/interface definitions the same source file (with only one of them public). Then is it accurate to say that no classpath would be needed because everything is in the source file that's specified on the command line? I really thought the compiler would choke on this, because it would be unable to find the actual class file -- even if the definition for that class was in the same source file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!