• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stack Overflow error

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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


 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic