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

Package question.

0 views
Skip to first unread message

Danny J.

unread,
Sep 11, 2000, 8:13:47 PM9/11/00
to
I have several classes under a package 'werkz'. But when ever I try to run
the program I get these exceptions.

D:\dev\werkz>java ClassName1
Exception in thread "main" java.lang.NoClassDefFoundError: ClassName1 (wrong
nam
e: werkz/ClassName1)
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)

What seems to be the prob?


Axel Liljencrantz

unread,
Sep 11, 2000, 6:41:22 PM9/11/00
to
You CANNOT directly run the main-method of a class that is part of a
package. You have to make a class that delegates the call to ClassName1.

Other gotchas with packages:
The base directory of the package must be in your classpath. Thus, in your
example the ClassName1-class should be located in
d:\dev\werkz\werkz\ClassName1.class

To access a class in another package it must be EXPLICITLY public.


hope this helps

/Axel Liljencrantz


"Danny J." <danny...@mindspring.com> skrev i meddelandet
news:8pjl74$q18$1...@nntp9.atl.mindspring.net...

Chris Smith

unread,
Sep 11, 2000, 5:58:27 PM9/11/00
to
"Axel Liljencrantz" <ro...@nasa.gov> wrote...

> You CANNOT directly run the main-method of a class that is part of a
> package. You have to make a class that delegates the call to ClassName1.

Hmm? Sure you can call it directly, so long as it's a public class.

> Other gotchas with packages:
> The base directory of the package must be in your classpath. Thus, in your
> example the ClassName1-class should be located in
> d:\dev\werkz\werkz\ClassName1.class

Of course, you probably want to just put d:\dev (or '.') in your CLASSPATH
and run the classes from the dev directory. Then you can leave the class
file where it is.

> To access a class in another package it must be EXPLICITLY public.

Yep.

And one other change to make. The command line must specify the package...
eg,

D:\dev\werkz>java werkz.ClassName1

HTH,

Chris Smith


Margalit Gur-Arie_elidan1

unread,
Sep 11, 2000, 7:09:37 PM9/11/00
to
"Danny J." wrote:
>
> I have several classes under a package 'werkz'. But when ever I try to run
> the program I get these exceptions.
>


You need to go one directory up (dev) and from there:

D:\dev>java werkz.ClassName1

0 new messages