This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package problem" Watch "Package problem" New topic
Author

Package problem

Jon Krogell
Greenhorn

Joined: Feb 12, 2001
Posts: 16
When I'm trying to import my own package I get this error:
"error: File /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/Car.class does not contain type Car as expected, but type stuff.jkrogell.Car. Please remove the file, or make sure it appears in the correct subdirectory of the class path."
Also, if I make a main method to the Car class, JBindery will give me this dialog box:
"Unable to launch java application.
The main class "Car" could not be loaded. Either it is not in the classpath or has a static initializer that uses a class not in the classpath."
I can't understand how it couldn't be in the Classpath.
So, what should I do to get this it to work.
Yeah, and if you didn't notice, I'm on Mac (OS 9.1) and I've got MRJ 2.24 and SDK 2.2 installed.
Thanks in advance.


mwaf @ <A HREF="http://dmoz.org/" TARGET=_blank rel="nofollow">http://dmoz.org/</A>
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Is this in your classpath?
/GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/
It sounds like you have this directory structure instead.
/GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/stuff/jkrogell

"JavaRanch, where the deer and the Certified play" - David O'Meara
Jon Krogell
Greenhorn

Joined: Feb 12, 2001
Posts: 16
Is this in your classpath?
/GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/

Yes. All the Java Runtime Classes are in there so I don't know how it couldn't be in the classpath. I've also manually added that folder to the classpath.
It sounds like you have this directory structure instead.
/GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/stuff/jkrogell

Nope, both the Car.class and Car.java files are in /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
What does your import statement look like?

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jon Krogell
Greenhorn

Joined: Feb 12, 2001
Posts: 16
My import statment looks like this:
import stuff.jkrogell.*;
In the Car class I have this package statment:
package stuff.jkrogell;

[This message has been edited by Jon Krogell (edited April 15, 2001).]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Hello Jon,
What directory are you in when you execute this? Do you have . in your classpath? If you are in the /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/ and . appears in your classpath before /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses It could cause the problem you are seeing. If you execute this from the /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses or any directory other than /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/ it should run.

------------------
Hope This Helps
Carl Trusiak, SCJP2


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Jon Krogell
Greenhorn

Joined: Feb 12, 2001
Posts: 16
There is no period ( . ) in the classpath. If you are referring to
Nope, both the Car.class and Car.java files are in /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/.
that period is the sentence ending period.
I'm compiling a Test.java file located in /GXP30/Desktop Folder/, it looks like this

Now the interesting thing is that the "import stuff.jkrogell.*;" isn't required, the I will get the error even if I haven't got it. If I change the import statement to "import stuff.jkrogell.Car;" it'll work, but none of the other classes in that package will. That won't work if the classpath doesn't include /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/stuff/jkrogell/ (I thought /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/ would do the trick, downloaded Jar files placed in that folder work with that in the classpath). Anyway, having "import stuff.jkrogell.*;" still doesn't work.
Jon Krogell
Greenhorn

Joined: Feb 12, 2001
Posts: 16
OK, it works now, the solution was that I had to JAR the the 'stuff' folder and place the JAR file in /GXP30/System Folder/Extensions/MRJ Libraries/MRJClasses/. I'm still wondering why it doesn't work without the JAR thing, it's a bit ineffective to JAR the whole thing (well, ok, it's not much but anyway) for every little change to the code.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Package problem
 
Similar Threads
classes in package cannot see other classes in same package
ho to set CLASSPATH if i am creating my own package
constructor to add to an array list
reasoning behind issues with protected fields in other packages
Creating Objects