错误总结:Exception in thread "main" java.lang.ExceptionInInitializerError

今天在理解工厂模式时出现了一个错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
	 at com.qyy.factory.UserAction.main(UserAction.java:11)
	Caused by: java.lang.NullPointerException
	 at java.util.Properties$LineReader.readLine(Properties.java:418)
	 at java.util.Properties.load0(Properties.java:337)
	 at java.util.Properties.load(Properties.java:325)
	 at com.qyy.factory.getBean.<clinit>(getBean.java:16)
	 ... 1 more

原因:读取配置文件内容时,其中的配置文件的全限定名写错,这类名字或路径最好复制全限定名,尽量不要手写,不要过分相信不会出错,哈哈

//读取配置文件内容
 private static Properties pro = new Properties();
 static{
 //小括号的名字书写错误
  	InputStream is = getBean.class.getResourceAsStream("/com/qyy/beas.properties");
  try {
   	pro.load(is);
  } catch (IOException e) {
  	 e.printStackTrace();
  }
 }

猜你喜欢

转载自blog.csdn.net/qyy_123456_qyy/article/details/83589803