[英]Nothing happens with this code. Why?
public void main(String[] args) {
System.out.println("Hello World!");
}
This compiles in my environment, but nothing happens at run time. 这可以在我的环境中编译,但是在运行时什么也没有发生。
If should be a static method, otherwise it can't serve as the entry point of a Java application. 如果应为静态方法,则该方法不能用作Java应用程序的入口点。
public static void main(String[] args)
------
{
System.out.println("Hello World!");
}
主要方法应为: public static void main(String[] args)
public void main(String[] args)
更改为
public static void main(String[] args)
main()
method syntax is, main()
方法的语法是
public static void main(String[] args)
you are missing static
, so JVM
not able to find your main()
method ie entry point so there is noting happened. 您缺少
static
,因此JVM
无法找到您的main()
方法(即入口点),因此没有发生任何事情。
Check your console It should display error message as 检查您的控制台它应该显示错误消息为
java.lang.NoSuchMethodError: main
Exception in thread "main"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.