This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hey ppl, picture this.... I have 3 java source files each starting with the same package declaration, and each defining a separate class (ClassOne, ClassTwo & ClassThree). They are saved in the same directory bearing the package name. ClassOne compiles fine. ClassTwo and ClassThree use instances of ClassOne and will not compile. (there is an error for every mention of the ClassOne instance) Does anyone know why the compiler can't see ClassOne? Cheers, Bob
It's likely a CLASSPATH problem. The parent directory of your package directory needs to somehow be included in the CLASSPATH value. Consider the following class definitions, where each class is defined in seperate source files, named the same as the classes, located in a directory named fubar.Sure, Foo.java can be compiled while working within the fubar directory, with a simple call to javac Foo.java. And as you've discovered, Bar.java cannot be (unless the parent directory of fubar is located in the CLASSPATH). A sure fire way to compile the dependent Bar.java source file, would be to change the working directory to the parent of the fubar directory, and using the command javac -classpath . fubar/Bar.java The . instructs the Java compiler to include the current working directory in the CLASSPATH. Since this directory contains the fubar directory (aka the fubar package), the fubar.Foo class definition was located during compilation. Note that it's possible that you don't need to explicitly specify the current working directory as demonstrated, since it may already be part of your CLASSPATH value. For more information on setting the CLASSPATH, take a look at http://test.javaranch.com/wiki/view?HowToSetTheClasspath [ March 17, 2004: Message edited by: Dirk Schreckmann ]
Dirk, you were absolutely right with the classpath solution! Everything was in order as regards system settings, but I was trying to access my code from the command line in completely the wrong way. Thanks so much for your help