The code you've shown doesn't give us enough detail to work with. Also, you didn't mention the error you are getting.

Please give us a more complete code snippet and also specify what exception you are getting.