Your code does not demonstrate your error leaving us completely in the dark as to figuring out how to help you. Consider creating and posting an SSCCE.