File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's exam ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic
Author

Dan's exam ...

Salim Mohamed
Ranch Hand

Joined: Sep 19, 2002
Posts: 55
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.
chintan desai
Greenhorn

Joined: Oct 16, 2002
Posts: 10
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

Joined: Sep 19, 2002
Posts: 55
Sorry for posting wrong piece of code. Thanks.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by Salim Mohamed:
Sorry for posting wrong piece of code. Thanks.

I was wondering why that code didn't look familiar.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's exam ...