Rehoboam got into trouble and lost a considerable amount of his pride at the hand of Shishak, king of Egypt. The strong cities that Rehoboam had established were lost to the Egyptians, and some of the wealth of the temple was taken too. Commendably, God's judgment against Judah elicited a humble response in the king's court (2nd Chronicles 12:6).
We are not always given an explanation concerning the causes of men's failures. I mean, we know that all of us are sinners by nature and so sin should never be a real surprise, but the immediate cause can sometimes be a bit of a mystery. Not so in this case. The reason behind Rehoboam's moral and spiritual failures is explicitly given in 2nd Chronicles 12:14, "He did evil, because he prepared not his heart to seek the LORD." So then, all that we need is to understand clearly how one is to go about "preparing his heart" to do this or that... particularly to seek God (Romans 3:11).
There are 2 men of whom it is said plainly that they did indeed prepare their heart to seek God: Jehoshaphat & Ezra (2nd Chronicles 19:3 & Ezra 7:10). Knowing that helps us some. We need only to examine their lives a little. It is apparent that these men had a wholesome direction in their lives. Their mindset was holy and pure. They had made up their minds that they were going to do right. But, Rehoboam didn't do that. The direction of his mind was wishy-washy.