Java 错误: Cannot make a static reference to the non-static method
This error occurs when you try to call a non-static method from a static context. In other words, you are trying to access an instance method without creating an instance of the class.
To fix this error, you can either make the method static or create an instance of the class and call the method on that instance.
For example, if you have a class called 'demo1' with a non-static method called 'qbChaXun()', you can create an instance of the class and call the method on that instance as follows:
demo1 obj = new demo1();
obj.qbChaXun();
Alternatively, you can make the method static by adding the 'static' keyword to the method signature:
public static void qbChaXun() {
// method code here
}
Then you can call the method directly from the class without creating an instance:
demo1.qbChaXun();
原文地址: https://www.cveoy.top/t/topic/f1Ej 著作权归作者所有。请勿转载和采集!