public static void main( String args[ ])
this code is compiling without any error but when i m executing it it give the folloing message :
exception in thread "main" java.lang.NoClassDefFoundError
Is there any istallation problem. if yes please please tell me the the right way to do it .
Please alter your log-on name to match the Ranch's naming policy.
Please write words in full "and" not "n".
Please put all quoted code inside CODE tags, because it makes it easier to read.
I presume you got that error message in response to writing
For the example you quote that is what you ought to write. It also presume it actually said
. . . NoClassDefFoundError Ex
because you must type the class name exactly the way it is spelt in the Java code, without a . or extension.
I don't think you have an installation problem; that usually produces an error message like "java is not recognised . . .". Please check your classpath that it contains a dot; on Windows it would include ;.; and on Linux/Mac/Unix :.: also making sure there are no extraneous spaces eg ; .; or :. :
I don't think it matters if the same thing appears twice in the classpath.
This is what it says about NoClassDefFoundError in the API
You haven't managed to move or delete the .class file, have you?
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
Explore the folder you happen to be in at the present, and make sure it contains files called Ex.java and Ex.class (or use "ls" in Linux, or "dir" on Windows which should show the folder's contents).
You will find details about setting up a very first program here in the Java Tutorials. Go through it, and look through the "common problems" bit. I think you have your PATH set up correctly already, but you can see how to set it in the installation instructions, here for Windows, it tells you how to set the PATH variable.
Welcome to JavaRanch!
First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. "Handles" aren't acceptable. You can change your display name here. Thanks!
As to your question: this is a very common problem. You, or some other software, has set the CLASSPATH environment variable (which tells Java where to look for class files) so that it doesn't include the current directory. You need an entry of just "." (a period) to stand for this. You might find this helpful.
I am aware that Marc is one of the most talented heads out there and
this question means i went wrong somewhere.
but i wanted to say that it is just a convention to have the class with the main method to be declared public.
No access modifier means the class has a default access.And in a Java file only on class can be public but there can be n number of non-public classes.
As far as i know..
Please correct me if i am wrong
Thanks in advance
Originally posted by Amit Ghorpade:
...it is just a convention to have the class with the main method to be declared public. No access modifier means the class has a default access...
Yes, it might be a good idea to make the main class public. But default access would not cause the problems that the original poster was having. So there's nothing "wrong" with the suggestion -- I just thought it needed some clarification about why "public" makes sense (which you provided above).