File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

java import packages question

Phil Lesh

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

|____ 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\ and 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"

Joined: Sep 29, 2000
Posts: 8521
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.

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

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 Source)
at Source)
at$100(Unknown Source)
at$ Source)
at Method)
at 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?
Phil Lesh

Joined: Oct 16, 2002
Posts: 17
P.S. the main class sits in the "App" dir and is called ""
I agree. Here's the link:
subject: java import packages question
It's not a secret anymore!