It's hard to say what's wrong without code. Your best bet here may be to show us your code. We don't want to see all of it, but rather
you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem, in other words, an
SSCCE (Short, Self Contained, Correct (Compilable), Example). For more info on SSCCEs please look here:
SSCCE