Masses of spherical nuclei from the energy-density method