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

Help NoClassDefFound error

0 views
Skip to first unread message

### Focus On Panama ###

unread,
Oct 1, 2005, 5:05:52 PM10/1/05
to
Hi,
I have installed the JDE & JRE 1.5 on my computer, the JAVAHOME
environment variable is set to the JRE directory. If I type java -version on
the command prompt I get the 1.5.xxxx message.

Created a simple class named "Main" in the package "javaencryptor" using the
NetBeans IDE 4.1. I am able to step through it until the end. Now, when I
try to run the same one from the command line it craps out! here are the
steps I follow:

1. Opened a DOS window on the directory where the Main.class file is (the
class is also named Main)
2. Checked that "java -version" shows the 1.5 version
3. typed "java -client Main" (but also tried "java -client Main.java" and
"java Main.class" and "java Main" but I get

Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name:
javaencryptor/Main)
at java.lang.ClassLoader.defineClass1(Native Method)
:
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

What am I doing wrong?


Andrew Thompson

unread,
Oct 1, 2005, 5:23:09 PM10/1/05
to
### Focus On Panama ### wrote:
...

> Created a simple class named "Main" in the package "javaencryptor" using the
> NetBeans IDE 4.1. I am able to step through it until the end. Now, when I
> try to run the same one from the command line it craps out! here are the
> steps I follow:
>
> 1. Opened a DOS window on the directory where the Main.class file is (the
> class is also named Main)
> 2. Checked that "java -version" shows the 1.5 version
> 3. typed "java -client Main" (but also tried "java -client Main.java" and
> "java Main.class" and "java Main" but I get

java -classpath .. javaencryptor.Main

'-classpath ..' tells Java your class can be found from the
parent directory of the *package* from which you are running
the class.

'javaencryptor.Main' tells Java to look for the class named
'Main' in the package 'javaencryptor'.

To run it from the *parent* directroy, you might type
java -classpath . javaencryptor.Main
..or..
java -cp . javaencryptor.Main
..or..
java javaencryptor.Main

BTW - Java's 'main(String[] args)' method makes 'Main'
a poor name for a class!

HTH

Tor Iver Wilhelmsen

unread,
Oct 1, 2005, 5:49:38 PM10/1/05
to
"### Focus On Panama ###" <tired...@abolish.now> writes:

> Created a simple class named "Main" in the package "javaencryptor"

So the fully qualified class name is "javaencryptor.Main".

> 1. Opened a DOS window on the directory where the Main.class file is (the
> class is also named Main)

That is not be the root of where the class is.

> What am I doing wrong?

You aren't using the real class name.

Roedy Green

unread,
Oct 1, 2005, 10:35:22 PM10/1/05
to
On Sat, 1 Oct 2005 23:05:52 +0200, "### Focus On Panama ###"
<tired...@abolish.now> wrote or quoted :

>Created a simple class named "Main" in the package "javaencryptor" using the
>NetBeans IDE 4.1. I am able to step through it until the end. Now, when I
>try to run the same one from the command line it craps out! here are the
>steps I follow:

Then something works in the IDE but not the command like this hints
the classpath is the problem. See
http://mindprod.com/jgloss/classpath.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Hemal Pandya

unread,
Oct 2, 2005, 5:40:10 AM10/2/05
to

Andrew Thompson wrote:

> BTW - Java's 'main(String[] args)' method makes 'Main'
> a poor name for a class!


Can you please explain why? Class Main is found in many packages (ant,
log4j, javac).

Roedy Green

unread,
Oct 2, 2005, 8:06:33 AM10/2/05
to
On 2 Oct 2005 02:40:10 -0700, "Hemal Pandya" <hemal...@gmail.com>
wrote or quoted :

>
>Can you please explain why? Class Main is found in many packages (ant,
>log4j, javac).

Because this is a newbie group and people are forever confusing
methods and classes and getting the naming conventions wrong.

Not only do you confuse newbies, we can't tell if you REALLY knew what
you were doing.

Further, the name Main suggests the starting class of a great set of
classes. It tells you nothing about what it does if it is the only
class.

### Focus On Panama ###

unread,
Oct 2, 2005, 9:11:44 AM10/2/05
to
Thanks! only I had to use "java -classpath ." instead because I was running
from the same directory the class was present. Somehow the java help lead me
to believe the classpath param was only if I needed classes from another
directory. It had been quite some years since I did some Java so many things
just dropped off my brain.

As for the poor name of the class, granted, it is a poor name but it is the
one NetBeans generated and since I was just trying some things out I did not
bother to change it.

Thanks!

Emilio
http://www.FocusOnPanama.com/

"Andrew Thompson" <seemy...@www.invalid> wrote in message
news:17D%e.4465$U51....@news-server.bigpond.net.au...

Andrew Thompson

unread,
Oct 2, 2005, 9:35:06 AM10/2/05
to
### Focus On Panama ### wrote:


> As for the poor name of the class, granted, it is a poor name but it is the

> one NetBeans generated ..

'Poor name', leading on to ..

>..and since I was just trying some things out I did not
> bother to change it.

..'poor excuse'. ;-)

> Thanks!

No worries. :-)

Hemal Pandya

unread,
Oct 3, 2005, 9:13:30 AM10/3/05
to

Roedy Green wrote:
>

Understood. All three points. Thanks for the explanation.

0 new messages