Java can't find method main

后端 未结 7 1998
孤街浪徒
孤街浪徒 2021-01-20 10:45

Im having trouble with a simple hello world program lol! Im hoping someone can shed some light on this.

So the error im receiving is the following:

$         


        
相关标签:
7条回答
  • 2021-01-20 11:22

    You forgot about [] in String[] argv or ... in String... argv. This array is used to store arguments used in command creating JVM for your class like

    java Hello argument0 argument1 argument2` 
    

    and so on.

    0 讨论(0)
  • 2021-01-20 11:23

    Your main method signature is wrong String instead of String []

    use

    public static void main(String[] argv)
    

    or

    public static void main(String... argv)
    

    read here

    0 讨论(0)
  • 2021-01-20 11:29

    Problem is that your method does not take String array as a argument. Use following signature instead:

    public static void main(String[] argv)
    

    or

    public static void main(String argv[])
    

    Other valid option is:

    public static void main(String ... argv)
    

    In Java Language Specification this is told as follows:

    The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.

    0 讨论(0)
  • 2021-01-20 11:37

    You forgot to put the array syntax, You can even use varargs as per JAVA 1.5

    public static void main(String... argv)
    
    0 讨论(0)
  • 2021-01-20 11:39
    public static void main(String[] args)
    public static void main(String... args)
    public static void main(String args[])
    

    Java programs start executing at the main method, which has the above method prototype

    0 讨论(0)
  • 2021-01-20 11:42

    Main method has signature that accepts String[] and you wrote String which is wrong,

    Make it

    public static void main(String[] argv)
    

    or varargs

    public static void main(String... argv)
    
    0 讨论(0)
提交回复
热议问题