This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes not able to run simple java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "not able to run simple java program" Watch "not able to run simple java program" New topic

not able to run simple java program

kesava chaitanya

Joined: Aug 20, 2001
Posts: 28
i have written simple java program;i am using JDK 1.3.1 version;i am running this program on WindowsME;i set the classpath properly;compiled well; but when i run the program i get the NoClassDefFoundError;how can i solve this problem
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
The surely looks like a Classpath problem. Make sure that everything is set properly (check capitalization, as well). If you have the class defined in a package, is it placed in the proper directory structure to mimic that package? (i.e. should be in C:\foo\bar\baz.)

SCJP Tipline, etc.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I've noticed that many programmers new to packages in Java will compile the source files just fine, put the class files in the appropriate directory structure according to the package declarations, then fail to run a specified class file from the appropriate directory.
In other words, if the file Hello.class belongs to the package fred and is in fact in a directory named fred, the programmer will try to run the class Hello.class from within the directory fred like so:
c:\fred>java Hello
c:\fred>java fred.Hello
which will not work. The proper place to run Hello from is from the parent directory of fred like so:
c:\>java fred.Hello
But perhaps this is not your problem...
Good Luck.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Another point to be wary of that could produce the exception that is causing you troubles:
Don't specify the .class file extension when running a Java program like this:
c:\>java Hello.class
rather do it like this:
c:\java Hello
Good Luck.
It is sorta covered in the JavaRanch Style Guide.
subject: not able to run simple java program