> However I can't understand what could be causing it!

Neither can we, unless you show us your code, and indicate the line that
generates the error.