This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package problem" Watch "package problem" New topic
Author

package problem

tyler jones
Ranch Hand

Joined: Dec 01, 2000
Posts: 101
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!
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Have you created a folder called divelog that is under whatever path you have set up? That would be my first guess, is it isn't finding the Welcome.class file in the location it should be.
Jason
tyler jones
Ranch Hand

Joined: Dec 01, 2000
Posts: 101
I have set up a folder called divelog right on my c drive. Do I need to update any files to locate it there?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
tyler jones
Ranch Hand

Joined: Dec 01, 2000
Posts: 101
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.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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).]
 
jQuery in Action, 2nd edition
 
subject: package problem
 
Similar Threads
Problem managing a loop with Swing app
Won't build a Jframe
Dynamically change tab color JTabbedPane
How to add new tabs from JMenu
Things arn't showing up...