My textbook states that the mean energy of free electrons within a solid state is given by $$ E_{av} = \frac{U}{N} = \frac{\int_0^{k_f}D(k)E(k)dk}{\int_0^{k_f}D(k)dk} $$ where $D(k)$ is the density of states and $k_f$ the fermi-wave-vector.
With $D(k) = \frac{m}{\pi^2\hbar^2}k$ and $E(k) = \hbar^2 k^2 /2m $ I receive $$ U=\frac{k_f^4}{8\pi^2} \, \,\, \, , \,\,\, N=\frac{m}{2\pi^2\hbar^2}k_f^2$$ thus $U/N = \hbar^2 k_f^2/4m = E_f/2 $ which is obviously wrong.
I don't see my mistake.
If I convert $D(k)$ in $D(E)$ with $E=\hbar^2k^2/2m$ and calculate $$U=\int_0^{E_f}D(E) E\, dE$$ and $$N=\int_0^{E_f}D(E)dE$$ I get the correct solution of $E_{av} = 3/5 E_f$.
What am I doing wrong? I am quite sure that I didn't do the calculations wrong, so the error must be caused by assumptions.