错误:java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException: inStream parameter is null
InputStream inStream = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
try {
properties.load(inStream);
} catch (IOException e) {
e.printStackTrace();
}
这是static代码块里的
检查过了db的名字和内容,没问题啊,为什么inStream为空啊
你这样:
ClassLoader.getSystemResourceAsStream("db.properties");
或者这样:
ClassLoader.getSystemResourceAsStream("resources/db.properties");
取决与resources目录在不在buildpath里,不清楚的话,都试一下
空指针是BaseDao.class.getClassLoader()为空导致的。
如果不是properties为空,则是地址不对,db.properties文件所在的包问题,BaseDao.class.getClassLoader()加载文件地址是src文件下的配置文件,如果在下级,需要添地址path/db.properties
Test01类里面是什么?