Two blocks of mass $m$ are attached to a spring of spring constant $k$. One of the blocks is compressed by $x_0$ and then released. The question is, what is the velocity of the block when the spring reaches its natural length. I calculated the velocity by two methods:
By energy conservation $$-\frac{1}{2}k{x_0}^2+\frac{1}{2}mv^2+\frac{1}{2}mv^2=0$$
Using Force $$-kx=ma=mv\frac{dv}{dx}$$
Integrating from $x_0$ to $0$, we get $$-\frac{1}{2}k{x_0}^2+\frac{1}{2}mv^2=0$$
It is clear that the $1^{st}$ method is correct but I am not able to understand at what step exactly the second method wrong?