wood burning stoves 2.0*
The moose likes Java in General and the fly likes java import packages question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java import packages question" Watch "java import packages question" New topic
Author

java import packages question

Phil Lesh
Greenhorn

Joined: Oct 16, 2002
Posts: 17
If I created a package structure like this:

App
|____ gui
|____ helper
|____ etc...

is it possible to import a class from package "helper" into "gui". I tied simply saying "import helper.*;" in one of the "gui" package class but it obviously didn't find it because "helper" package is on the same level as the "gui" package. Also i tried setting the packages like so: "App.gui" & "App.helper". The reason why I want to do this is I want to separate all the button/panel/etc creations and place them in gui package and have things like listeners in a different package comprised of classes with static methods which the gui components can access. Thank you very much for your help.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Yes, you can definitely do that - it does not matter if you import a class on the same level, a lower level, a higher level, or even in a completely different package structure.
This sounds more like a problem with your classpath. If you have C:\work\App\gui\MyComponent.java and MyComponent.java has package and import statements like:

Then your classpath should contain "C:\work".
Hope that helps


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
philphilphil,
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
Phil Lesh
Greenhorn

Joined: Oct 16, 2002
Posts: 17
When packages are named App.gui, App.helper and compilation/running takes place outside the App directory, the compilation works fine, but with the command "java App.TheApp", I get the following error:
J:\>javac App\*.java
J:\>java App.TheApp
Exception in thread "main" java.lang.NoClassDefFoundError: App/TheApp (wrong name: TheApp)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Can anyone help?
thanks
Phil
Phil Lesh
Greenhorn

Joined: Oct 16, 2002
Posts: 17
P.S. the main class sits in the "App" dir and is called "TheApp.java"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java import packages question