File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes java.lang.StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "java.lang.StackOverflowError" Watch "java.lang.StackOverflowError" New topic


Sandy Abraham

Joined: Aug 27, 2003
Posts: 9
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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

If you cut-and-pasted the stack trace here, we could probably tell you, but without it, we'd just be guessing.

[Jess in Action][AskingGoodQuestions]
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
(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.
I agree. Here's the link:
subject: java.lang.StackOverflowError
It's not a secret anymore!