如何在主类中调用非静态方法。示例控制台应用程序中出现以下错误
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method doSomthing() cannot be referenced from a static context
at sample.Main.main(Main.java:20)
代码是,
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
doSomthing();
System.out.print("From Main");
}
protected void doSomthing()
{
System.out.print("From Main doSomthing");
}
}