Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes classes in package cannot see other classes in same package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classes in package cannot see other classes in same package" Watch "classes in package cannot see other classes in same package" New topic
Author

classes in package cannot see other classes in same package

k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Hi
I have the following as part of my classpath:
c:\javatemp
in the javatemp folder i have a folder called rental. Every java file in rental has as the first line so this should be enough for all the classes to be part of the rental package. However when i try to create an object of for example class Car i get a class not found error this is despite the line
Have i missed something, I recently added to my classpath, i'm using windows 2000, should the addition to my classpath be immeidiate or do i need to reboot/login-logout?
Any ideas why the classes cannot see each other (but compile) they are also all public
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I'm a little confused: is the "import rental.Car" in a class in the rental package itself? It's definitely not necessary, in that case, and I'm not altogether sure it's allowed.
Note that you'll have problems if "rental" is your current directory when you're compiling; you want to compile things from the javatemp directory, like "javac rental\*.java" .

i'm using windows 2000, should the addition to my classpath be immeidiate or do i need to reboot/login-logout?

If you made this addition to your CLASSPATH via the control panel, then it should take affect for any console windows opened after the change is made, but not for those that were already open. Otherwise it sounds like you're doing the right things.
[ August 26, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

EFH: I'm a little confused: is the "import rental.Car" in a class in the rental package itself? It's definitely not necessary, in that case, and I'm not altogether sure it's allowed.
I agree that it's not necessary, since you don't need to qualify classes in the same package, but it is allowed. (I just tested it )
EFH: Note that you'll have problems if "rental" is your current directory when you're compiling; you want to compile things from the javatemp directory, like "javac rental\*.java" .
As long as C:\javatemp is in the classpath, there should be no problems compiling from the "rental" directory. I do this sort of thing all the time.

Anyway, as Ernest suggested, try closing the console window and opening a new one to see if that solves the problem. If it doesn't, please cut-and-paste the exact error that you are getting so that we can all see it -- that will greatly aid our diagnosing the problem.
Thanks.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Guys
Thanks for the replies. I did think that the import was unneccesary as the classes are all in the same package. I have since removed the import statement. I rebooted my PC over night and I still get the following error:

which points to the following line in rentalCentre.java:-

I've double checked Vehicle and it is definetly part of the same package, I've also double checked my classpath and it appears to be okay. DOes the above line seem okay?
THanks
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Okay
I've just noticed that when i compile it inside JBuilder -classpath switch does not include the folder i added to the classpath does this mean that when using this switch, any packages which are part of the current classpath are ignored and only the ones which follow the switch are used?
I compiled it outside JBuilder and i get different error messages (but it does recognise the classes) so i'm thinking this is the problem.
Thanks guys for your help
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

That is indeed the problem: the -classpath switch overrides the system CLASSPATH.
If you have difficulties with any of your other problems, just let us know. We're glad to help.
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
Thanks for the input, i guess my only other question is does anyone know how to specify what is included in the classpath switch when compiling using JBuilder

Thanks
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Not sure -- I don't use JBuilder myself. You might try posting that question in the IDE's and other tools forum; you'll probably get a better response.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
does anyone know how to specify what is included in the classpath switch when compiling using JBuilder
Project -> Project Properties... -> Path Tab -> Required Libraries Tab -> Use the Add... button to your heart's content.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classes in package cannot see other classes in same package
 
Similar Threads
Am i missing something here?
Bad Class Error
Help on NoClassDefFoundError
JBuilder: set -classpath when compiling
ServletUtilities class