catching nullpointerexceptions while looping over categories

This covers the exception that was giving me trouble.