Aside from injuries and diseases that affect the joints (such as arthritis), there are essentially two basic reasons for joint pain: either the muscles surrounding the joint are weak or there's a lack of flexibility.

Fortunately, you can address both problems with the same solution: strength training. Working out regularly with weights will gradually strengthen the muscles. And by doing the exercises with proper form -- that is, working the joint through its full range of motion -- you can improve flexibility.