This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
My guess is that you get a StackOverflowError. When you call floodFill(3, 3, c1, c2), that will call floodFill(2, 3, c1, c2). If this also matches then it in turn will call floodFill(3, 3, c1, c2). This won't end.
You need to keep track of all the pixels you already handled, or otherwise ensure that you only handle each pixel once.
the above is the error that gets generated
and if the stack memory gets overflow the how to stop it is there any method or technique in Java
and its not possible to keep a track of each and every pixel since in large regular/irregular shapes it is impossible
I wish I could insert the image to make my error understand better??
That's not a stack trace, that's only part of it. Not even the most interesting part which always comes at the top.
It's most definitely possible to keep track of all the pixels you've already changed. You just need to find a way how to. The most basic way is to create a boolean with the same dimensions as your image, then set the right value if you've encountered it. That's probably not the most efficient way though.
As for adding images, you can't link to images on your local hard drive. The Ranch allows you to upload image attachments; just check the Attachments tab just below the post field.