Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

package problems

1 view
Skip to first unread message

Dan Sketcher

unread,
Jan 30, 2001, 9:33:55 PM1/30/01
to
I'm having a problem with running a class that is within a package.
Basically i've included a main() in a class for debug and the class works
fine when it's not in a package and it's invoked at the command line.
However, as soon as i put it in a package, it no longer runs on the command
line.

for example:
--- package to be referenced
package c05.local;
public class PackagedClass {
public PackagedClass() {
System.out.println("Creating a packaged class.");
}
}
---
--- referencing package
//package c05.foreign; // (1)
import c05.local.*;
public class Foreign {
public static void main(String[] args) {
PackagedClass pc = new PackagedClass();
}
}
---
Now if these are off the classpath in the directories appropriate for the
packages and line (1) is commented out,
"java Foreign" produces output of:
"Creating a packaged class."
However, if line (1) is uncommented, the output is:

Exception in thread "main" java.lang.NoClassDefFoundError: Foreign (wrong
name:
c05/foreign/Foreign)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

Any ideas? I'm running sun jdk 1.3.0.

Cheer,
Dan Sketcher.

ps. Thanks to Bruce Eckel for a great java book.

--
_________________________________________________
Mr Dan Sketcher
P.O. Box 10114,
Brisbane, Adelaide St,
QLD 4000
AUSTRALIA
email: dansk...@hotmailSPAM.com (remove the SPAM)


Dan Sketcher

unread,
Jan 30, 2001, 9:35:30 PM1/30/01
to

Cheer,
Dan Sketcher.

phone: +61 7 3876 8962


email: dansk...@hotmailSPAM.com (remove the SPAM)

mobile: 0416 265 235


Chris Smith

unread,
Jan 30, 2001, 9:54:31 PM1/30/01
to
The parameter to the Java interpreter is the fully qualified class name of
the class to run. If the class is called Foreign and it's in the
c05.foreign package, then the fully qualified class name is
c05.foreign.Foreign -- you need to give Java the right class name.

It also appears that you've got your classpath set incorrectly. The
directory containing Foreign.class should not be in your classpath. The
directory containing the "c05" directory should be in your classpath. Java
will automatically look in the c05/foreign subdirectory because that's the
package that the class is in.

Chris Smith


Dan Sketcher

unread,
Jan 30, 2001, 10:56:58 PM1/30/01
to
Thanks Chris :)

0 new messages