• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error message wehn i run the code  RSS feed

 
Bassam Bibo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Chhabra, welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!