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.
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"
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
Joined: Oct 16, 2002
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
Joined: Oct 16, 2002
P.S. the main class sits in the "App" dir and is called "TheApp.java"