Problem With Package
I have a package called Product that has 2 class files, ProductInfo and BinaryFile. Both files are located in the same directory ../Product/ and both files start with "package Product;" I can compile BinaryFile.java just fine. Inside of ProductInfo i want to use the class BinaryFile, however i get a compile error saying:
I did not think an import was needed since the files are in the same directory and in the same package, does any one have any ideas on how to fix the compile error?
ProductInfo.java:18: cannot find symbol
symbol : class BinaryFile
You mean BinaryFile and ProductInfo are in the same package, but can't access ProductInfo within the BinaryFile class?
Yes both classes are in the same package called Product but it is the other way around. ProductInfo has BinaryFile variables in it. Each product has a preview image so for example inside of ProductInfo there is a variable: BinaryFile previewImage = new BinaryFile('/path/preview.png');
For the compiler to find a class, the class must be on the classpath. For a class in a package, the classpath must end where the package begins, so that the classpath + package path is the location of the class file.
For example class X in package pkg located on path: C:\javastuff\pkg\X.class would require a classpath of C:\javastuff.
If you use javac with -classpath . the . would be a classpath of C:\javastuff\pkg.