Debugged iteration 5

Added if else statement to catch the null pointer to show a error
message