1.Make the method staticpublic static String restore(String str4) {
String m_str="123";
return m_str;
}a static method can not call non-static method directly.
2.Initialize the object firstU should make a new bean first.
Urbean bb = new Urbean();
bb.restor("4356");
String m_str="123";
return m_str;
}a static method can not call non-static method directly.
2.Initialize the object firstU should make a new bean first.
Urbean bb = new Urbean();
bb.restor("4356");
~~~~~~~~~
不能在静态static函数中引用非静态方法
因为static函数在class初始化之前调用
静态方法:
(1)仅能调用其他的static方法;
(2)只能访问static数据;
(3)不能以任何方式引用this或super
C:\wwwroot\WEB-INF\classes\mydb.java:126: non-static variable conn cannot be referenced from a static context
conn= DriverManager.getConnection(sConnStr,user,password);
^
public static void main(String[] args) {
String iop= restore("4563");
} public static String restore(String str4) {
String m_str="123";
return m_str;
}
就行了。