Shyam, A stack overflow usually means an infinite loop or code that calls itself. Once in a while, it means you are just using too much memory. It's good practice to rule out the common causes before looking at the memory. And you aren't doing anything memory intensive.
Try simplifying the code to see if the error still occurs. For example, what happens if you comment out the loop with index "k". If the problem still occurs, you can comment out more code. If not, you know where to examine more closely.
When you post java code and want us to look at it, we'll all thank you if you enclose the code in [ c o d e ] [ / c o d e ] tags (without the spaces). This will preserve the indents in your code and make it infinitely easier to read.