Imagine a Rectangle class with public width and height fields. Any code can set width = -3. Your area calculation returns a negative number, and the bug might not surface until much later.
Now make those fields private and add a setter:
public void setWidth(int w) {
if (w > 0) {
width = w;
}
}
The bug is now impossible. Every write goes through setWidth, which rejects invalid values at the source. When a bug does appear, you only need to check one method instead of searching your entire codebase for every place that modifies width.
Encapsulation turns field access into a funnel. One entry point, one set of rules, fewer bugs.