I have a problem when I read about the Essential Supremum of a measurable function. Let $f: E\longrightarrow \mathbb{R}$ is a measurable function respect $E$ is Lebesuge measurable set and the Lebesgue measure. Let $$ \operatorname{ess sup} f = \inf\{z: f\leq z\;\text{almost everywhere}\}$$ We always have $\operatorname{ess sup} f \leq \sup f$, but when $f$ is continuous, why $\operatorname{ess sup} f = \sup f$?
I assume that $\operatorname{ess sup} f < \sup f = \alpha < \infty$, then exist $z$ such that $f\leq z$ almost everywhere and $z < \sup f = \alpha$, then the set $A = \{x\in E: f(x) > z\}$ is a null set, so the set $B = \{x\in E: \alpha > f(x) > z\}$ is also a null set, but $B = f^{-1}\big((z,\alpha)\big)$ is an open set in $E$. But since a set $B$ is open in $E$ if and only if exist an open set $V \subset \mathbb{R}$ such that $$ B = V\cap E$$ Now, I can't find any contradiction?, for exmaple, if $E = \mathbb{R}$ then I have a contradiction since $B$ is open and not empty which can't be a null set. But if $E$ is a null set of $\mathbb{R}$, why is contradiction?