This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.