InputStream is = getClass().getClassLoader().getResourceAsStream("dbconnect.properties");
Properties properties.load(is);以上两句在普通类中没有问题,在静态方法中,提示getClass()不能使用,请问各位高手,有什么替代的解决办法?

解决方案 »

  1.   

    如果你用的类是
    public class Main {
    }那么就写成Main.class替换 getClass()就行了。
      

  2.   

    up  不太清楚您要表达的意思     不知道LZ可否把此类代码帖出看一下       
      

  3.   

    类编写如下:用1楼方法改写public class test { private static Properties properties = new Properties(); public static void main(String[] args) { try {
    InputStream is = test.class.getClassLoader().getResourceAsStream(
    "dbconnect.properties");
    properties.load(new FileInputStream("dbconnect.properties"));
    String strUrl = properties.getProperty("connection.url");
    WriteLog(strUrl);
    } catch (FileNotFoundException e) {
    WriteLog("配置文件不存在!" + e.getMessage());
    } catch (IOException e) {
    WriteLog("读取配置文件IO错误!" + e.getMessage());
    }
    } public static void WriteLog(String strLog) {
    System.out.println(strLog);
    }}报错:Exception in thread "main" java.lang.UnsatisfiedLinkError: com.test.java.Sample1.intMethod(I)I
    at com.test.java.Sample1.intMethod(Native Method)
    at com.test.java.test.main(test.java:15)