Handle null pointer exception when getting a dictionary value