Evaluating surface integral (1) directly and (2) by applying Divergence Theorem give different resoluts I have a vector field $\mathbf{A}(r) = \frac{1}{r^2}\mathbf{a}_r$. I am interested in finding the flux through a sphere enclosing some volume with radius $R$ and center at $r=0$.


*

*Calculating the divergence of vector field $\bf A$, I get zero divergence. 

*Integrating the zero divergence over the volume of a sphere with radius $R$, I get zero net flux. 

*But when I integrate the vector field over the surface, I get $4 \pi$.



*

*$$\Rightarrow \nabla \cdot \mathbf{A} = \frac{1}{r^2} \frac{\partial (r^2 \frac{1}{r^2})}{\partial r} = \frac{1}{r^2}\frac{\partial}{\partial r}(1)= 0$$


$$\int_V \nabla \cdot \mathbf{A}\ dV = \oint_S \mathbf{A}\cdot d\mathbf{S}$$ 


*$$\int_V \nabla \cdot \mathbf{A}\ dV = \int_V 0 \ dV = 0 \,?$$

*$$\oint_S \mathbf{A}\cdot d\mathbf{S} = \oint_S A\mathbf{a}_r\cdot \mathbf{n}_s dS = A(r)\oint_S dS$$
Sphere with radius R:
$$A(R)(4\pi R^2) = \frac{1}{R^2}4\pi R^2= 4\pi \neq 0$$
If the volume integral of the divergence of the field is zero, it means that the field is constant inside the sphere, or that the field strength inside the sphere in total grows and shrinks by the same amount.
If the surface flux integral of the vector field is equal to some positive constant, then the magnitude of the field is not constant on the boundary of the sphere. This means that the field at some point has to grow more than it shrinks inside the sphere, resulting in a divergence $\neq 0$. 
So obviously $4\pi \neq 0$... What is happening here?
 A: The hypotheses of the Divergence Theorem require that the vector field be defined and $C^1$ on all of the solid $V$, but here the vector field ${\bf A} := \frac{1}{r^2} {\bf a}_r$ is not defined at zero (indeed, as $r \to 0$, $\bf A$ is unbounded). Thus, the Divergence Theorem does not apply. The computation $$\iint_S {\bf A} \cdot d{\bf S} = 4 \pi$$
is, by the way, correct (for the usual outward-pointing orientation of the sphere $S$).
There's an analogous example for Green's Theorem: The vector field $${\bf X} := \bigg(\underbrace{-\frac{y}{{x^2 + y^2}}}_P \partial_x + \underbrace{\frac{x}{{x^2 + y^2}}}_Q \partial_y\bigg)$$ satisfies $\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} = 0$, but the contour integral along the unit circle (oriented anticlockwise) is $$\oint_{\Bbb S^1} {\bf X} \cdot d{\bf s} = 2 \pi,$$ which does not coincide with $$\iint_D \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) dA = 0,$$
where $D$ represents the unit disk. Again, there is no contradiction, because $\bf X$ is badly behaved near zero and so does not satisfy the hypotheses of Green's Theorem.
