David was in a protected place at that time. The Philistine army was staying in the town of Bethlehem.