Suppose a mass of $M$ kg is hanging from a spring in earth. The mass will stretch the spring about $x$ m. So the change in the gravitational potential energy is $mgx$ J (supposing $x$ to be very small compared to the radius of earth).
And this amount of energy will be stored in the spring as potential energy. So,
Change of gavitational energy = $mgx$ = potential energy stored in the spring
And it seems that the potential energy stored in a spring is proportional to displacement $x$. But the potential energy in a spring is $U=\frac{1}{2}kx^{2}$ and so it's proportional to $x^2$, the square of displacement. So surely I am wrong somewhere. But where am I wrong?