Make sure that your GUI is initiated before connect statement.

Post your class code, there will be some hidden mistakes.