David showed no hostility toward God, and he tried hard to change whenever he could see that he was wrong. However, he could not always see it. For instance, David stole Bathsheba, the wife of Uriah, and she became pregnant. After conniving and cheating in an attempt to avoid the consequences, David intentionally arranged for Uriah to be killed in battle.
Incredible as it may seem, David did not see how terribly wrong his sexual immorality in both his thoughts and actions was. He broke both the spirit and letter of the law. Not until the prophet Nathan brought him to his senses did spiritually blind David realize his sinful behavior.
Nevertheless, we cannot judge David too harshly, since our vision is likewise clouded regarding many of our problems. It is hard enough to recognize and admit the problems we can see, much less the ones we cannot. Rather than judge him, we can actually identify with David.