For some arbitrary constant $a$, the question is: $$\int_{0}^{ \pi} \frac{x}{a^2- \cos^2(x)} dx$$
I was able to bring it down to: $$I=\frac{\pi}{2}\int_{0}^{ \pi} \frac{1}{a^2- \cos^2(x)} dx$$
I tried to solve on by dividing $\cos^2(x)$ on numerator and denominator and we would get (taking $I_1$ to be the integral part) $$I_1=\int_{0}^{ \pi} \frac{\sec^2(x)}{a^2(1+\tan^2(x))-1} dx$$
Now assuming some value $t= \tan(x)$ we can solve this but substituting the limits when $x=0,\; t=0 $
$ x=\pi,\; t=0$ gives us integrating a function from the same starting to ending point which would yield us a value of $0$, but the answer is not $0$ and, in fact, there is no graph such that the area can be zero.
Why does this apparent value of $0$ appear in doing this integral in this way?
For $|a|\leq 1$ the integral is improper as said in the comments, but for $|a|>1$ the function $x\mapsto \frac{1}{a^2-\cos^2(x)}$ is positive and continuous, so its integral on any bounded interval cannot be zero.
Before yo do your substitution, you need to realize that the tangent is not defined for $x=\pi/2$, so you need to split the integral into two integrals: $$ J=\int_0^\pi \frac{1}{a^2-\cos^2(x)}\; dx = \int_0^{\pi/2} \frac{\sec^2(x)}{a^2(1+\tan^2(x))-1}\; dx + \int_{\pi/2}^\pi \frac{\sec^2(x)}{a^2(1+\tan^2(x))-1}\; dx $$ and when making the substitution $t=\tan(x)$ and changing the limits of integration in the first integral you obtain the integral from $0$ to $+\infty$ and in the second integral the limit from $-\infty$ to $0$, because $$ \lim_{x\to \frac{\pi}{2}^-} \tan(x) = +\infty \quad \text{and} \quad \lim_{x\to \frac{\pi}{2}^+} \tan(x) = -\infty. $$ So you obtain $$ J= \int_{0}^{+\infty} \frac{1}{a^2(1+t^2)-1}\; dt + \int_{-\infty}^{0} \frac{1}{a^2(1+t^2)-1}\; dt = \int_{-\infty}^{+\infty} \frac{1}{a^2(1+t^2)-1}\; dt, $$ so the mistake is in not to split the integral for the undefined value of the tangent.