Exception in thread "main" Java.lang.NoSuchMethodError: main? [duplicate]
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)
精彩评论