It can be caused by a condition caused luxating patella, where the channel the knee cap sits in is too shallow and it slips out instead of running back and forward along the channel. It is hereditary and dogs showing this condition should not be bred from. Many small breeds suffer from it and it can be operated on but most people don't bother. Luxating patellas can also occur as a result of an accident. In many countries, the dogs are tested for this like we test for hips/eye problems.