Hi all,

I am new to Java, I have written a small Java program; as far as my knowledge the program seems to be alright. When I compile the program, it compiles without any complain. However, when I try to run it, from OS command prompt, I get the following error message:

bash-2.03$ javac CountSession.java
bash-2.03$ java CountSession
Exception in thread "main" java.lang.NoSuchMethodError: main

Any inputs, comments and suggestions will be greately appreciated.

Thanks and regards.

9 Years
Discussion Span
Last Post by new_2_java

Thanks for reply,

If the main method is missing in my program and/or if I have a typo error (mis-spell), imy program shouldn't compile in the first place. However, like I mentioned, my program compiles without any error; it throws an exception, when I try to run it.

Plus the interface that I am using, is included in my CLASSPATH system environment variable.

Thanks and regards.


No, it will compile just fine without it. main, as far as the compiler is concerned, is a method just like any other, but when you try to execute a class and the method definition public static void main(String[] args) does not exist, you will get the exact error message you are showing. The method must be defined exactly as above with the following possible variations

1) args can be any name you want, it does not have to be exactly args 2) String[] args may also be String args[] (keeping point 1 in mind)

Those are the only variations allowable (as they are not really variations, the definition is the same, it is just typed a little differently). Having something else will prevent you from executing your program, but it will still compile with ease.


Thanks for your reply,

I figured that the interface that I was using, wasn't in my CLASSPATH system environment variable. So, I had to put the full path of my interface into CLASSPATH, and then re-compile my program. After, it start working fine.

Thanks alot for your participation and replies.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.