Java 中的堆栈溢出错误
Possible Duplicate:
What is a stack overflow error?
What does it mean when there is a StackOverflowError in Java?
java.lang.StackOverflowError: null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 Java API Documentations for the
StackOverflowError< /code> class
,“当由于应用程序递归太深而发生堆栈溢出时”会抛出此错误。
According to the Java API Documentations for the
StackOverflowError
class, this error is thrown "when a stack overflow occurs because an application recurses too deeply".通常意味着存在一个递归函数,其中结束条件永远不会发生。它会运行,填充堆栈,直到出现 StackOverflowError。
Usually means there is a recursive function where the end condition never happens. It runs, filling the stack, until you get a StackOverflowError.
这意味着您已将太多帧推送到 Java 解释器堆栈上。 JVM 可以处理相当深的嵌套函数深度,但迟早您需要划清界限并说:“如果您嵌套的东西比这更深,您的程序可能会行为不当”。你越过了那条线。
查看是否使用任何递归函数调用,然后在其循环等效项中重写它们(如果需要)。不必要的递归函数是引发堆栈溢出异常的 90% 原因。另外,请记住,Java(尚未)优化尾端递归(这是其他环境避免堆栈溢出/失控堆栈增长的方式)。
It means that you have pushed too many frames onto the Java interpreter stack. The JVM can handle a depth of nested functions that goes pretty deep, but sooner or later you need to draw the line in the sand and say, "if you nest things deeper than this, your program is probably misbehaving". You crossed that line.
See if you're using any recursive function calls, then rewrite them in their looping equivalents (if necessary). Unnecessarily recursive functions are 90% of the reasons you throw a stack overflow exception. Also, keep in mind that Java doesn't (yet) optimize tail end recursion (which is how other environments avoid stack overflows / runaway stack growth).
这意味着堆栈(系统跟踪已执行内容的方式)已溢出(尝试放入的内容超出了允许的内容)。这通常意味着您有一个无法控制地调用自身的递归操作。
It means that the stack (the way the system keeps track of what has been executed) has overflowed (more was attempted to put on in than was allowed). This frequently means that you've got a recursive operation that's uncontrollably calling itself.