The account of David committing adultery with Bathsheba opens thus: “In the spring of the year, the time when kings go out to battle, David sent Joab with his officers and all Israel with him; they ravaged the Ammonites, and besieged Rabbah. But David remained at Jerusalem.”
Take note of that last bit, “but David remained in Jerusalem.” That’s where the trouble begins.