繁体   English   中英

为什么我的代码中会出现java.lang.StackOverflowError?

[英]Why am I getting java.lang.StackOverflowError in my code?

在我的java类中,我有一个名为getProperties()static方法,它返回java.util.Properties

在另一个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语句。

我执行代码没关系,但我认为Exception in thread "main" java.lang.StackOverflowError的错误Exception in thread "main" java.lang.StackOverflowError ,也许是导致问题的原因。

Properties p = new Properties();
FileInputStream fs = new FileInputStream("src/main/resources/fileName.properties"));
p.load(fs);

发生StackOverflowError是因为您的代码多次调用静态方法,您是否可以发布整个代码以便我们可以看到为什么getProperties方法没有达到返回? 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM