This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I'm working on a program that displays different shapes on the canvas with a class called "Driver". I have a method called "toggle" that makes the shapes look like they're randomly twinkling by removing and then bringing back the visibility of a shape in the class called "Star". Unfortunately when i came back to work on the code today, the method "toggle" seems to not work anymore and i can't figure out what went wrong. My guess is i might have unintentionally removed a piece of code or when i added on more code i might've ruined the toggle method is someway. Can someone please help me out and see if you can find the problem? I have a feeling its something minuscule or obvious but i've just about given up on trying to figure it out myself!
There's not enough code shown to see what is happening ie what draws the shapes? what thread is this run on? etc etc
I suggest you add print statements at various places in your code so you can confirm that toggle is being called and is called at a rate that would allow you to see the twinkle. Also add prints in the drawing code to check the background is being drawn over the star (or however you remove it) etc.
Not that this is of any use to you right now but this type of problem highlights the advantages of using an RCS or at the very least zipping up the code each time you get to a milestone - at least then you can revert back to an earlier working version or use diff to see what you have changed.
will give an ArrayOutofBoundsException, and the control will not go to the loop after it that is doing the toggling. WHen you have an array of size 20, the index can go from 0 to 19, not from 0 to 20. In the last iteration of the loop, you will be accessing array which will cause an exception
ArrayOutofBoundsException is a runtime exception, and you are not catching it, so control must be going outside of the run method. My guess is that code is terminating the thread somehow and not logging the exception.
Add more logging in your code, and also change the terminating condition on that loop to i<20
Joined: Aug 07, 2007
Well spotted Jayesh. The OP didn't mention any exceptions so I didn't even look for anything that might throw one.