原文:【踩坑】報錯 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