One very simple solution to ensure that your knees stay pain-free during and after exercise is to keep your quads (the front of your thighs stretched out). See, your quad muscle attaches from your hip and goes all the way down your thigh finishing just over the knee. If this muscle is tight, it pulls your kneecap upwards causing pain and discomfort.
How to stretch your quads:
Stand on an even surface, and grasp your right ankle with your right hand, pulling your heel in towards your bottom. Squeeze your bottom tight, push your hip forward and ensure that your knee is pointing down towards the ground. You should feel a stretch down the front of your thigh. Hold this stretch for 30+ seconds, and repeat before and after exercise.
Of course if this stretch does not alleviate your knee pain after a few days, it may be time to get an expert opinion from a sports therapist.