Spraying is not a litter box problem but, rather, a communication system cats use to mark territory. To prevent spraying, consult your vet about possible medical causes. Also, consider getting your cat neutered. But first, try to identify the reasons he or she might be spraying (yes, even females can have this nasty habit). Triggers may include:
Be sure to not punish your cat, even if caught in the act of spraying, as this will likely lead to more spraying.