Given $X = \operatorname{Uniform}(0, 4)$ distribution where the distribution is continuous.
Using the definition for $\operatorname E(X)$
\begin{align} & \operatorname E(X) \\[10pt] = {} & \int_{-\infty}^\infty xP(X\in dx) \\[10pt] = {} & \int_{-\infty}^\infty xf(x)\,dx \\[10pt] = {} & \int_{-\infty}^\infty x\frac 1 {4-0} \, dx \\[10pt] = {} & \int_{-\infty}^\infty \frac 1 4 x \, dx \\[10pt] = {} & \text{undefined?} \end{align}
But the textbook is like $E(X)=\frac{a+b}{2} = \frac{0+4}{2}$ ?
Definition of $E(X)$ for continous distributions:

The density is $f(x) = \begin{cases} \dfrac 1 4 & \text{if } 0<x<4, \\ \\ 0 & \text{otherwise}. \end{cases}$
Therefore \begin{align} \int_{-\infty}^\infty xf(x) \, dx = \int_{-\infty}^0 x\cdot0\,dx + \int_0^4 x\cdot\frac 1 4\, dx + \int_4^\infty x\cdot0\,dx. \end{align}
You should never write $\text{“}{= \text{undefined.''}}$ You should say that something is undefined, not that it is equal to something called "undefined". This is the "is" of predication, not the "is" of equality.