錯誤總結: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();
  }
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章