File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Error message wehn i run the code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Error message wehn i run the code" Watch "Error message wehn i run the code" New topic
Author

Error message wehn i run the code

Bassam Bibo
Greenhorn

Joined: Jul 14, 2011
Posts: 1
Hello dear friends,

i just start with java "Head first java from sierra & bates" the german version. wehn i start the code "after compiling" in the first example i get this error message :

Exception in thread "main" java.lang.NoSuchMethodError: main


and this is the code what i use :



can somebody tell me where my fault is?


PS: sorry for my bad bad english

Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 530
In the main public class in the file with the same name that you've called at the command line, Java looks for a method called main() with the signature



as the starting point for program execution. If the file containing the class you run does not have the main() method, you'll get the error you posted.

That should be explained in your book.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32689
    
    4
It says at the bottom of page 3 "you'll be writing real code in a minute". Maybe it should have said "you can't execute the Party class as it stands".
Eduardo Hernandez
Greenhorn

Joined: Jul 09, 2011
Posts: 13

The entry point of a Java program is the main method, the signature of main must look like this: public static void main(String[] args) { }. When you execute (run) a java program the JVM looks for the main method in your class (program) to start executing your program's instructions if it can't find the main method definition the JVM complains and displays that error.
Shubham Chhabra
Greenhorn

Joined: Jul 19, 2011
Posts: 6
The main() method is the entry point in the program. So you have to put main method in your program. If you do not put main()method your program will compile put will not run. The java interpreter will search for main method and call JVM to load the nessary classes and interfaces. You have to put the main method in some class.


public static void main(String s[])
{
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32689
    
    4
Shubham Chhabra, welcome to the Ranch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Error message wehn i run the code
 
Similar Threads
Bad Version Number in .class file
Party.java in HeadFirst Java p. 3
noob needs help with path
Help with First Java Code - Party.Java
class-file not executing