This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package problem

 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic