• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Dan's exam ...  RSS feed

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ManyClasses {
public static void main(String[] r[]){
System.out.println("Hi");
}
}
class basic1 {
public static void main(String[] r[]){}
}
class basic2 {
public static void main(String[] r[]){}
}
class basic3 {
public static void main(String[] r[]){}
}
This doesnt cause compilation error. But I dont understand why this is causing runtime error :
Exception in thread "main" java.lang.NoSuchMethodError: main
even if this is stored in a file called ManyClasses.java.
Thanks in advance.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Salim,
This is because the main method in Class named ManyClasses is not the "public static void main(String args[])" , from where any program starts execution. The main method in this program is overloaded version of the "public static void main(String args[])" method, which has argument parameters as "String[] r[]" which is two dimensional array and that's not the correct syntax for main method. that's why it is compiling but giving error at runtime that there is no such main method with "String r[]" which has one dimentional String array.
Chintan.
 
Salim Mohamed
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting wrong piece of code. Thanks.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Salim Mohamed:
Sorry for posting wrong piece of code. Thanks.


I was wondering why that code didn't look familiar.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!