We have a thin, grounded, metallic spherical shell. While solving for its total energy using the formula
$$U_E = \frac{\epsilon_0}{2}\int|\mathbf{E}|^2\,\mathrm d^3r$$
the book I am following says that the electric field outside the shell is zero. But I think Gauss's law doesn't allow that as any spherical Gaussian surface larger than the shell will enclose a net charge of $q$.
If the field is indeed zero outside the shell, then the charge at the center must somehow be cancelled. I don't understand how can the grounding of the shell cancel the charge. Can anyone explain why this happens?