Knee pain during exercise can be quite frustrating and a little limiting but it should not stop you exercising completely.
Commonly, the pain is a result of your knees doing too much work and taking too much pressure. Repeated impact, bouncing around, running on hard surfaces and poor technique in the gym all can cause knee pain if the surrounding musculature is not strong enough.
The solution?
Stop impact exercises. All running and jumping should be cut out for the short term.
Mobility work for the ankles and hips. Both these joints are intended to be mobile. If they are underused they will become stiff and not function properly during exercise. This is where your knees will start to then over-compensate.
Hip Dominant exercises. In the gym, you will need to perform exercises that target the glute and hamstring muscles and require minimum to no effort from your knees.