God called David a person after His own heart. A person after God's own heart is not a perfect person, but rather a person that when they see their sin, repents right away.