I'm working through a tutorial on Sun's website and it has you create one main class and about 6 or so other classes all in a package called divelog. Although I haven't created my own packages before, I understand the concept. So, I have one class like this...
and then my main class that tries to use this class....
When I try to compile the DiveLog.java file, I get an error that divelog.Welcome not found along with all the other classes called in the populateTabbedPane() method of the code when it says new Welcome(), new WebSite(), etc. Can anyone suggest a reason why I can't get this to compile. I've even tried copying all the code for all the classes from the tutorial pages and I still get the same error. Thanks!
Hi Tyler, When you compile start one directory above divelog and use the -d option. For example, if your directory structure is
and both <code>Welcome.java</code> and <code>Divelog.java</code> are in <code>c:\javadev\divelog</code>; make sure you are in <code>c:\javadev</code> and then compile using
The -d option tells the compiler to put the .class files in the directory matching the package name; it will search for the <code>divelog</code> directory starting from the current directory. If you compile from within the <code>divelog</code> directory itself it will look for another <code>divelog</code> directory below it. When you run the program, again, start one level above the <code>divelog</code> directory and enter
Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
Thanks Jane. That worked fine after a bit of tweaking. So, can you explain to me why I couldn't compile from within the package itself? Thanks again.
Joined: Aug 30, 2000
Hi Tyler, The compiler expects to find the directories corresponding to the package names below the current directory. When you start in <code>divelog</code> the compiler will look for another a subdirectory named <code>divelog</code>. For example, it will expect to see
It always searches from the current directory. If you use a classpath it will begin it's search from the last directory in the classpath. For example, if your classpath was <code>x:\dir\divelog</code> it would still look for another subdirectory <code>divelog</code> starting the search at <code>x:\dir\divelog</code>. Hope that helps.
[This message has been edited by Jane Griscti (edited October 20, 2001).]