In addition to frame size, using to high or hard a gear combination can cause leg and/or knee pains. When I learned to spin at 80 to 95 rpm, I quit having most issues I had with leg and knee pain. That's not to say I can maintain that high cadence over the entire ride, but I'm working on it.
Having your seat too high and hyper extending your leg on the extreme down stroke of the pedal can be frequent causes too irregardless of frame size.
Not drinking fluids during the ride? There is some debate on whether it causes cramps or not, but whenever I feel certain types of leg pain or back pain I find it goes away if I increase my water intake.
You are using muscles differently than you do for other stuff, so they may just not be used to it yet.
But no matter what, you need to give some more info......
Your bike type, road, hybrid, mountain, whatever? Your current frame size? Your inseam floor to snug in the crotch with or without shoes but let us know which. Your height?