在我的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