Since nobody answered your post, two hints:
(a) You can indicate that you have a question by a single '?'
(b) Your code contains, kindof, an error. However what kind of error it is requires detailed information, not some code which you considier similar to the one with the problem and the complete error messages. So post the code (best practice - that is, most likely leading to an usable answer - is to extract a minimal example containing the error which everyone can copy into one file and compile & execute for himself) and the error you get.