This could be an issue of pedaling too hard. I started cycling, and when I first started, I was pedaling at a low cadence (pedal rotations/minute, I was probably at < 60, I didnt have a bike computer then) and would get knee pain on shorter rides (~5 miles). Now I ride between 80-115 cadence on rides over 20 miles and experience no pain. The other problem is that the bike wasn't properly fitted for you.