Fixed null pointer exception in onMessage() function