David's heart was afflicted because he realized he had acted very foolishly and committed a great sin.