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");

解决方案 »

  1.   

    public static String restore(String str4) {
           ~~~~~~~~~
    不能在静态static函数中引用非静态方法
    因为static函数在class初始化之前调用
      

  2.   

    main是静态方法。
    静态方法:
    (1)仅能调用其他的static方法;
    (2)只能访问static数据;
    (3)不能以任何方式引用this或super
      

  3.   

    你将restore方法声明成静态方法即可
      

  4.   

    可声明成 static 后里面的好多语法不能用了例如:
    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);
        ^
      

  5.   

    是呀,改成
    public static void main(String[] args) {
      String iop= restore("4563");
      }  public static String restore(String str4) {
      String m_str="123"; 
      return m_str;
      }
    就行了。