Answer :

It means accusing the wrong person
AL2006
When dogs are chasing racoons or squirrels, the things they're chasing run up into trees
to escape, and then the dogs gather around the base of the tree and bark and howl up
at them.

If it's at night, it can happen that the dogs lose sight of them, but continue to follow their
scent (smell) for a few seconds.  That may be just long enough for the squirrel to make a
sharp turn and go where the dogs don't know he went, and into a different tree. Then
you have a hilarious sight:  The pack of dogs are all jumping and howling and barking up
into a tree, and the squirrel is up in a different tree watching them.

The dogs are literally barking up the wrong tree.

It means: ==> Pursuing the objective in the wrong direction.  You've somehow been
distracted or deflected from a productive course, and you're looking in the wrong
place for the object of your pursuit or search or goal.