# Integral of a product of a ${L^1}_{loc}$ function and a compact support function

I'd like to prove that, if $$f\in {L^1}_{loc}(\mathbb{R}^n)$$ and $$g$$ is a bounded, measurable function with compact support and if $$\int_{\mathbb{R}^n} fgdx = 0$$ $$\forall g$$, then $$f$$ is almost everywhere equal to $$0$$.

Surely $$fg\in L^1(\mathbb{R}^n)$$: by hypothesis, $$|g|\leq c\in\mathbb{R}$$, so we have

$$||fg||_1=\int_{\mathbb{R}^n} |fg| dx\leq c\int_{K}|f|dx\leq +\infty$$, where $$K$$ is the support of the function $$g$$. So I applied Lebesgue differentiation theorem to $$fg$$, in order to have

$$lim_{r\to 0^{+}} \frac{1}{|B(x,r)|} \int_{B(x,r)} f(y)g(y)dy = f(x)g(x)$$ almost everywhere, but now I don't know how to use the hypothesis about the integral of this product over $$\mathbb{R}^{n}$$. How can I proceed?

Let $$g$$ be bounded, measurable and have compact support. Define $$A := f^{-1} ([0,\infty)) \in \mathcal B (\Bbb R^n)$$. Then $$g\cdot 1_{A}$$ is a measurable, bounded function with compact support. Hence $$0=\int_{\Bbb R^n} f g 1_{A} = \int_{\Bbb R^n} f ^+ g ,$$ where $$f^+$$ is the positive part of $$f$$. Thus, without loss of generality we can assume that $$f\geq 0$$. Now let $$g = 1_{B(0,r)}$$ with $$r>0$$. The function $$g$$ is bounded, measurable and has compact support. Therefore, $$\int_{B(0,r)} f =0.$$ Since $$f\geq 0$$, this yields $$f = 0$$ almost everywhere on $$B(0,r)$$. This means there exists a null set $$N_r \subseteq B(0,r)$$ with $$f(x) = 0 \quad \forall x\in B(0,r) \setminus N_r .$$ This provides $$f(x) = 0 \quad \forall x \in \bigcup\limits_{m=1}^\infty ( B(0,m) \setminus N_m) \supseteq \Bbb R^n \setminus \bigcup_{m=1}^\infty N_m.$$ Since $$\lambda (\bigcup_{m=1}^\infty N_m) \leq \sum_{m=1}^\infty \lambda (N_m) = 0$$ we have that $$f=0$$ almost everywhere.
Since $$g = 1_{B(x,r)}$$ is measurable and bounded with compact support you could also proceed with your idea as follows:
$$\int_{B(x,r)} f = \int_{\Bbb R^n} fg = 0$$
Thus for almost every $$x\in\Bbb R^n$$ $$0 = \lim_{r\searrow 0} \frac{1}{\vert B(x,r)\vert} \int_{B(x,r)} f = f(x)$$