原文:【踩坑】报错 non-static method xxx() cannot be referenced from a static context

今天测试代码时遇到 Error: , java: non static method sayGoodbye cannot be referenced from a static context 的报错,代码如下: 原因: 不能直接调用类变量和类方法。 解决方法一: 将方法改成类方法,如下: 解决方法二: 生成实例,调用实例中的非静态方法,如下: ...

2019-03-25 16:38 0 9361 推荐指数:

查看详情

Cannot make a static reference to the non-static method的解决方法

报错原因:在一个类中写了一个public String getContent()方法和一个main()方法,getContent()方法中包含了getClass()方法,在main()方法中直接调用了getContent()就出现如题的错误。这样一样 解决方法:先实例化类,然后再 ...

Tue Jan 12 18:42:00 CST 2016 0 1899
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM