Depends if it is a painful "crack" or not.
The painful variety often feels more like a "clunk" than a "crack"
The cause for this is often an inflamed tendon moving over the joint. This occurs with the hip, for example. Treatment could involve non-steroidal anti-inflammatory drugs or even cortico-steriod tablets or injections (either systemic or local - directly into the joint).
If you're referring to the (non-painful) "popping" sound that your knees or ankles sometimes make when you squat etc. this is most commonly caused by nitrogen bubbles in the joint. I'm not sure if there is, or needs to be, a "fix".