This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help!!! I know packages cant be this difficult. :-( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help!!! I know packages cant be this difficult. :-(" Watch "Help!!! I know packages cant be this difficult. :-(" New topic

Help!!! I know packages cant be this difficult. :-(

C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
I am trying to understand packages but its getting a bit difficult.

...compiles fine

Why is my second class giving me this compile error?
package com.example.test does not exist
[ February 23, 2005: Message edited by: Crusty Magmanum ]
Joe Ess

Joined: Oct 29, 2001
Posts: 9124

Crusty, can you change your displayed name to conform to the JavaRanch
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake. You can do that here.
Now, about packages. Unless you tell the compiler differently, it will write the class file it generates into the current working directory. Packages work like the file system, so if you have a package named com.example.test, the compiler will expect to find classes in that package in a directory named com/example/test under the current one (or in the classpath, but that's another story). To have the compiler do this automatically, compiler with the -d flag and specify a directory ("." for the current directory is fine). Consult the Java Tutorial chapter on Packages for more info.
[ February 23, 2005: Message edited by: Joe Ess ]

[How To Ask Questions On JavaRanch]
marc weber

Joined: Aug 31, 2004
Posts: 11343

You might also refer to the chapter on packages in Bruce Eckel's Thinking in Java...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I suspect that the issue is with your directory structure in the file system. Packages correspond to directory names, so for the example you gave, you should have the following structure:

You can compile all of your classes from C:\java:

If is not compiled or has been modified, javac should detect this and compile it before it compiles

If this doesn't help fix your problem, please describe the directory structure you are using. Hopefully it will help us think of other things you can try.

Keep Coding!

[ February 23, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
Thanks so much for ur suggestions but I'm still not getting anything positive. This is my commandline input

c:\>javac -classpath /somefile/foo.jar -d classes

The structure is how u suggested but I am not sure how -classpath (in the commmand-line) affects the import in mum calls me crusty
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Help!!! I know packages cant be this difficult. :-(
It's not a secret anymore!