Java cannot find method main

I have a simple hello world plan trouble ha ha! I hope someone can understand this

Therefore, the errors received are as follows:

$javac Hello.java
$java Hello
Exception in thread "main" java.lang.NoSuchMethodError: main

Therefore, through the error, I can see that it obviously lacks the main, but it is there:

class Hello
{
  public static void main(String argv)
  {
    System.out.println("hello world");
  }
}

If there's any help, I'm on Mac OS / X

Solution

The problem is that your method does not take a string array as an argument Please use the following signature instead:

public static void main(String[] argv)

or

public static void main(String argv[])

Other valid options are:

public static void main(String ... argv)

In the Java language specification, this is told as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>