File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Package confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package confusion" Watch "Package confusion" New topic

Package confusion

Kasem Boonmun

Joined: Dec 14, 2003
Posts: 4
1. My classpath is .;C:\j2sdk1.4.0\bin
2. I write base class named "person" and create "test" directory in "C:\j2sdk1.4.0\bin" and again put "person" class in.
3. Create another class called "manager" which inherits from "person class in "test" package and create "test2" directory in "C:\j2sdk1.4.0\bin" and again put "manager" class in.
What i got while compiled "manager" class is "package test does not exist" error. Would you please help me out?
Thanks in advance


Joined: Sep 30, 2003
Posts: 3
Sorry I find some problem in your script..
1. no main method , you can't execute manager class if it can be complied.
2. If your package is test ,it's mean the script include of the package(the test directory) , so you just can import test.* or another directory and class include of the test if they exist.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I�m not sure why you are receiving that error. That error is usually indicative that you have a classpath problem, but your classpath looks fine. However, you didn�t mention what command you were using to compile with.
Verify your classpath is being properly read by running the command:
C:\> echo %CLASSPATH%
It should return the classpath you specified above. If it does, the command
C:\j2sdk1.4.0\bin>javac test2\
Should properly compile your class. If the echo command does not return the proper classpath you found your issue.
If you still have problems, try specifying the classpath at compile time by using the following command:
C:\j2sdk1.4.0\bin>javac -classpath .; C:\j2sdk1.4.0\bin test2\
That should resolve the problem. If it does, you will need to double/triple check your classpath entry in your environment variable to make sure it is correct. (Sometimes the easiest thing is to delete the entry and retype it fresh).
Yusure is correct that neither of your classes are directly executable since neither has a main method. Regardless, they should still compile.
Good Luck...
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
(Not offering any answers...)
Your example compiles fine for me as well.
Let me suggest not using the j2sdk/bin directory for your source files. This bin folder is supposed to be the location of binary executable files used by the j2sdk. You're not hurting anything, it would just seem to make a bit more sense to keep Java source files in a location like java/projects or java/source. Just a suggestion...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Package confusion
It's not a secret anymore!