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.
(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.