在我的java類中,我有一個名爲getProperties()
的static
方法,返回java.util.Properties
。爲什麼我在代碼中得到java.lang.StackOverflowError?
在另一個static
方法,我調用該方法,如:
Properties p = getProperties();
而且getProperties()
方法:
private static Properties getProperties(){
Properties properties = new Properties();
try{
InputStream fis = null;
fis = new FileInputStream("src/main/resources/fileName.properties"); //In DEBUG mode control comes until here and returns to Properties p = getProperties(); in the calling method every time continuously
properties.load(fis);
fis.close();
}catch(Exception e){
//......
}
return properties;
}
錯誤:
Exception in thread "main" java.lang.StackOverflowError
at sun.misc.VM.isBooted(VM.java:165)
at java.util.Hashtable.initHashSeedAsNeeded(Hashtable.java:226)
at java.util.Hashtable.<init>(Hashtable.java:263)
at java.util.Hashtable.<init>(Hashtable.java:283)
at java.util.Properties.<init>(Properties.java:143)
at java.util.Properties.<init>(Properties.java:135)
雖然在調試模式下的GetProperties() ;方法被連續調用而沒有達到return語句。
你正在使用哪個Java版本? – Kayaman
不直接相關:將'fis.close();'移至(不存在的!)'finally'子句。如果您遇到異常,您將打開FileInputStream。 – Emz
你能分享該文件的內容嗎?那裏可能會有些時髦嗎? – Mureinik