堆栈溢出错误?

时间:2011-06-04 12:06:05

标签: java

我正在开发一个帐户申请表。当我试图运行发票表格时,发生了一个叫做堆栈溢出异常的事情...告诉我该怎么做...我想在Stock类中声明发票对象之前一切都很好。 这是输出......

run:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
    at sun.awt.Win32GraphicsConfig.getBounds(Native Method)
    at sun.awt.Win32GraphicsConfig.getBounds(Win32GraphicsConfig.java:215)
    at java.awt.Window.init(Window.java:394)
    at java.awt.Window.<init>(Window.java:433)
    at java.awt.Frame.<init>(Frame.java:403)
    at java.awt.Frame.<init>(Frame.java:368)
    at javax.swing.JFrame.<init>(JFrame.java:158)
    at Invoice.<init>(Invoice.java:10)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)

    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
    at Stock.<init>(Stock.java:670)
    at Invoice.<init>(Invoice.java:1135)
BUILD SUCCESSFUL (total time: 5 seconds)

2 个答案:

答案 0 :(得分:17)

Invoice构造函数中,您正在创建一个新的Stock对象(在第1135行)。

Stock构造函数中,您正在创建一个新的Invoice对象(在第670行)。

Invoice构造函数中,您正在创建一个新的Stock对象(在第1135行)。

依此类推,直到达到最大堆栈深度。您需要确定InvoiceStock中的哪一个应该自动创建另一个的新实例,或创建对象然后将它们分配给彼此。

答案 1 :(得分:2)

嗯..在我们回答你之前我们需要看一些代码,但是当你有一些代码调用自己而没有结束时会发生stackoverflow异常(Recursion,没有进展)。所以你应该看看你的代码,并找出它应该在什么条件下终止循环,以及为什么它还没有这样做:)