I think a great way to avoid setbacks when starting to train for races is to make sure you incorporate adequate stretching into your program. Generally when a person is training for a specific race they will increase their weekly mileage and also the intensity of their running. This is necessary to prepare for the race, but with this comes added stress on your muscles and joints. Increasing the time you spend running can also lead to cutting back on the amount of time you spend stretching. If you really have a hard time stretching on your own make it a point to fit a yoga class into your weekly workout routine.
An effective way to avoid training hiccups like shin splints and knee pain is to cross train. Cross training means mixing up the types of exercises you do and the equipment you choose. For example, the bicycle or elliptical are excellent non-impact training modalities that could be used in between running or sprint training, which are high-impact and tougher on the joints.
A good exercise to help avoid knee pain, shin splints, and other ailments when training for races is to foam roll! It will help to loosen up tight muscles and knead out knots to help you recover faster and avoid injury.