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.

You either missing method main in your program or made mistake in speling of it

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.