When someone is barking up the wrong tree it means that the person is wrong about something and no matter how much you try to persuade someone about what you're trying to say it's not gonna change anything because you're wrong about something.
Basically barking up the wrong tree means that you are making a wrong assumption about someone or something.
Or you could be barking up the wrong tree when you accuse someone of something when you have no proof about it or when they didn't actually do what you're accusing them of.
So in that case if you accused someone of stealing or taking something or doing something and it turned out you're wrong then you'd be barking up the wrong tree.