GameLayer中的Stackoverflow错误

时间:2013-09-16 10:06:43

标签: java android cocos2d-iphone stack-overflow

浏览后我知道Stackoverflow错误是由于方法的递归调用,这是我的代码,我得到上述错误,但无法解决这个问题。

public static GameLayer sharedGameLayer() {
    return sharedGameLayer();
}

logcat错误

09-16 15:13:30.074: E/AndroidRuntime(1597): FATAL EXCEPTION: main
09-16 15:13:30.074: E/AndroidRuntime(1597): java.lang.StackOverflowError
09-16 15:13:30.074: E/AndroidRuntime(1597):     at com.ps.GameLayer.sharedGameLayer(GameLayer.java:533)
09-16 15:13:30.074: E/AndroidRuntime(1597):     at com.ps.GameLayer.sharedGameLayer(GameLayer.java:533)
09-16 15:13:30.074: E/AndroidRuntime(1597):     at com.ps.GameLayer.sharedGameLayer(GameLayer.java:533)
09-16 15:13:30.074: E/AndroidRuntime(1597):     at com.ps.GameLayer.sharedGameLayer(GameLayer.java:533)

1 个答案:

答案 0 :(得分:4)

您的方法以递归方式调用自身,导致您的堆栈用完。