You could compare my code example to yours and try to find the difference or are you also seeing this error using my code snippet?
If you cannot find the issue, feel free to post an executable code snippet which reproduces the error.