• 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

java.lang.StackOverflowError

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I wrote a class for MyCanvas which has the paint method.
And i have another class 'HandleCanvas' which extends MyCanvas and implements KeyListener. In MyCanvas i wrote addKeyListener(new HandleCamvas()). Everything compiles ok. except that when i actually execute it, there's this java.lang.StackOverflowError in main. From what i know, it's because of some recursive method calling. But I am not sure where went wrong. Please help. Thanks.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you cut-and-pasted the stack trace here, we could probably tell you, but without it, we'd just be guessing.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1) HandleCanvas extends MyCanvas implements KeyListener
(2) MyCanvas -> addKeyListener(new HandleCamvas());
When (2) is called, you have to create a new instance of HandleCanvas - which intern makes a call to its super class constructor, MyCanvas().
And I guess, you would have added the listener (2) in the constructor of MyCanvas.
So, you have to create another instance of HandleCanvas for adding keylistener - and the process continues.. until stack gets full.
reply
    Bookmark Topic Watch Topic
  • New Topic