开发者

Exception in thread "main" Java.lang.NoSuchMethodError: main? [duplicate]

This question already has answers here: "Error: Main method not found in class MyClass, please define the main method as..." (10 answers) Closed 9 years ago.
import java.io.*;
import java.lang.Math;
class Squr
{
  public static void main ()
  { 
   int m =10,n;
   double z = 10.4,p;
   Squr square = new Squr();
   p = (double)square.mysqrt(z);
   n = (int)square.mysqrt(m);
   System.out.println ("square root of 10 : " + n );
   System.out.println ("square root of 10.4 : "+ p );  
  }
    double mysqrt (double y)
   {
     return Math.sqrt(y);
   }
   int mysqrt (int x)
   {
     return (int)Math.sqrt(x);
   }

}

This code is compiling but when we try to execute it it g开发者_运维知识库iving " Exception in thread "main" Java.lang.NoSuchMethodError: main "


The main() function should be declared like this

public static void main(String[] args)


The correct method signature for the main method in Java is:

public static void main(String args[])

Simply add the missing arguments in you method declaration and it should work.


Try that:

public static void main(String [ ] args)


It looks like you've not defined your main method with the correct signature. It should be:

public class Squr
{
  public static void main(String[] args)


Your main() method should be like that

public static void main(String args[])

or

public static void main(String[] args)

or

public static void main(String... args)


Java is a strong type language. You must declare the method in a given way. The right way to define the main() method is:

public static void main (String[] args)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜