I rarely get knee pain from riding, but when I have, it has been related to bad fore/aft positioning (in my case, this usually means being too far forward, but that will depend on your body and your bike).