Have you ever seen a dog chase a cat up into a tree? The cat can jump into another tree once it is high enough, but the dog at the bottom might not know.
Instead, it will continue barking (吠叫) up the wrong tree.
People make similar mistakes. For example, many foreign teachers thought living in China would be very difficult because they didn't know the language.
However, they found out they were barking up the wrong tree, because there were so many people who were helpful and kind to them when they arrived.