To bark up the wrong tree means to make an error in trying to succeed in something or in judging somebody.
1. When the policeman did not find any proof that the arrested man was a drug dealer, he realized that he was barking up the wrong tree.
2. When days of digging in the ruins turned up nothing, the archaeologist realized his team was barking up the wrong tree.