Means pursuing a mistaken or incorrect course of action, often when trying to find a solution or solve a problem.
“Thinking my toy was under the bed, I was barking up the wrong tree and it was actually on the shelf.”