Declare variable chk to fix null problem.