User blog comment:Superdadsuper/Life Lessons from David and Bathsheba/@comment-44137425-20191015045856/@comment-5175866-20191015134528

All people, even believers are capable of sin. Indeed, Christians (or in the days of David, "Yahwists") have a different/greater power over sin and reason not to sin. Nonetheless, the flesh is still part of the struggle of the Christian life, as is the attacks of evil spiritual forces.

David is called a "man after God's own heart", because he sought to obey God in his rule over Israel, compared to Saul who was self-seeking. The phrase also indicates that the general direction of David's life was one of obedience.

1 Kings 15:5 is very insightful, it tells us that David walked with God his entire life, except in matter of his adultery. Yes, David commited other sins along the way (like the census he took). But in David's life, there was only one instance where he completely stopped walking with God altogether for a time- his adultery. Read my post that talks about that verse specifically in more detail.

God can call someone a "righteous" man, but that does not mean everything we do is righteous. Righteousness is imparted solely by the work Christ did and is measured by the general actions of our life- did one generally seek to obey God or follow self. I hope this helps answer your question.