java.lang.NoClassDefFoundError

That's the error message i get in the runtime mode.

I'm sure most of you guys had experienced that error since it actually come up in my Helloworld program...-_-'

yes, i am a beginner in Java, had a little c++ basics, but i'm not too familiar with Java, still learning now...hope to study it a little better, so...hope i can learn a lot from you guys =)

Anyway, bout the error...

It happened in my helloworld program below

public class Helloworld

{

public static void main(String[] args)

{

System.out.println("Hello World!");

}

}

I thought it was because i didn't put a constructor in it. I try to put 1, but nothing changed. Though i thought a main program doesnt need a constructor, since no object is gonna call the main program anyway, but well, no harm in trying right =P

So, can anyone help me?

Sorry if my english bit slank =P

My question review :

1> why did the error message "java.lang.NoClassDefFoundError" appear in my helloworld program?

2> Does a main class need to have a constructor?

Hope to hear positive comment and replies to my questions from allllll u guys =)

thanks for da help yo...=D

[1232 byte] By [CruxBlacka] at [2007-11-26 17:36:41]
# 1
Why are you posting this question in a forum whose description is:"Discussion area for topics relating to troubleshooting of JavaSE and applications in enterprise deployments."?
TimRyanNZa at 2007-7-9 0:04:48 > top of Java-index,BigAdmin,Troubleshoot...
# 2

Hi

Have you compiled your .java file using javac command?

if not you have to compile the .java file first and then run the file with java without any extension.

Say for eg:

public class HelloWorld{

public static void main(String ar[]){

System.out.println("Hello World!");

}

}

Save the file as "HelloWorld.java"

To compile:

javac HelloWorld.java

After running this (above) command you can see a .class file is created with the same file name(.java file name).

i.e HelloWorld.class will be created for you at the same path.

To Run the program:

java HelloWorld

Output:

HelloWorld!

If you directly run the program without compiling the source code(.java file) you will get the below error:

"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"

Guess... you got the answer.

njoy!!

chriscsita at 2007-7-9 0:04:48 > top of Java-index,BigAdmin,Troubleshoot...