• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stack Overflow error  RSS feed

 
Alex Garci
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a Stack Overflow error in this code and I don't know why:


 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somewhere your code is going into an infinite loop. I can't tell where, because it's in code you haven't posted. But the sort of things to be looking for are methods that call themselves, or objects that, when created, cause the creation of another instance of the same class (e.g. if Venta had a member variable of type Venta that was initialised with a new object).
 
Alex Garci
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,

I mistook for the button. I continue explaining the problem:


I have a Stack Overflow error in this code and I don't know why:





When I run this code I displayed the error:

Exception in thread "main" java.lang.StackOverflowError
at java.lang.String.<init>(Unknown Source)
at java.lang.StringBuffer.toString(Unknown Source)
at java.text.DecimalFormat.expandAffix(Unknown Source)
at java.text.DecimalFormat.expandAffixes(Unknown Source)
at java.text.DecimalFormat.applyPattern(Unknown Source)
at java.text.DecimalFormat.<init>(Unknown Source)
at java.text.NumberFormat.getInstance(Unknown Source)
at java.text.NumberFormat.getNumberInstance(Unknown Source)
at java.util.Scanner.useLocale(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Venta.<init>(Venta.java:14)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)

How can I fix it?

Thanks.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, then the error is exactly what I said it might be. Have a look at line 14 of your Venta listing. That means every time you create a Venta object, that contains a new Venta object, which contains a new Venta object....etc. That keeps going until the amount of memory set aside for the execution stack runs out - a "stack overflow".
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Garci wrote:Exception in thread "main" java.lang.StackOverflowError
at java.lang.String.<init>(Unknown Source)
at java.lang.StringBuffer.toString(Unknown Source)
at java.text.DecimalFormat.expandAffix(Unknown Source)
at java.text.DecimalFormat.expandAffixes(Unknown Source)
at java.text.DecimalFormat.applyPattern(Unknown Source)
at java.text.DecimalFormat.<init>(Unknown Source)
at java.text.NumberFormat.getInstance(Unknown Source)
at java.text.NumberFormat.getNumberInstance(Unknown Source)
at java.util.Scanner.useLocale(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Venta.<init>(Venta.java:14)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)
at Venta.<init>(Venta.java:17)

How can I fix it?

Thanks.


Look at the repeating line in that stack trace. What happens in Venta.java on line 17? [edit] or rather line 14 which starts it all...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!