File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static modifier doubt

 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The above code is given in chapter 2, page no:147. It gives input a a a. But I got runtime exception:Exception in thread "main" java.lang.NoSuchMethodError: main

Can anyone explain?
 
Deepak Jain
Ranch Hand
Posts: 637
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have had both the classes defined in the same java file named StaticTest.java.Here in StaticTest.java has one public class StaticTest and one default class Static. After compilation two class files will be generated StaticTest.class and Static.class.
And now you would have run the below cmd
java StaticTest
This will result in the exception , because the class StaticTest does not have the main method.

Fix would be do swap the access modifiers of the classes and rename the class to Static.java
OR
java Static
will give the desired result. This will now look for the main() in Static.class and will find and execute it.

Thanks
Deepak
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepak. I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic