Now we have to look into our crystal balls to give you advide unless you post the code fragment that causes this error.
As a general rule, Yashas, if you've got a problem please post the error message if any and the code that is causing the problem. In the best case it is a SSCCEE. The more information you provide, the more likely someone can help you.
http://sscce.org/