Barking up the wrong tree

Barking up the wrong tree is an idiomatic expression in English, which is used to suggest a mistaken emphasis in a specific context. The phrase is an allusion to the mistake made by dogs when they believe they have chased a prey up a tree, but the game may have escaped by leaping from one tree to another. The phrase means to mistake one's object, or to pursue the wrong course to obtain it.

In other words, "if you are barking up the wrong tree, it means that you have completely misunderstood something or are totally wrong."

Historical usage
Barking up the wrong tree became common use in nineteenth century America in reference to hunting raccoons with a hunting dog. When the nocturnal animal takes to a tree, the dog is supposed to remain at the base of the tree until its owner arrives. However, in the dark, if the dog mistakes the tree where the raccoon has taken refuge, the hunter may lose it. The expression was commonly used by writers of western life and tales, appearing in works by James Hall, David Crockett, and Albert Pike.
 * 1833 – "It doesn't take a Philadelphia lawyer to tell that the man who serves the master one day, and the enemy six, has just six chances out of seven to go to the devil. You are barking up the wrong tree, Johnson."—James Hall, Legends of the West, p. 46.
 * 1833 – "I told him that he reminded me of the meanest thing on God's earth, an old coon dog barking up the wrong tree." – Sketches of David Crockett, p. 58. (New York).
 * 1834 – "[The Indians] to use a Western phrase, barked up the wrong tree when they got hold of Tom Smith."
 * 1838 – "Instead of having treed their game, gentlemen will find themselves still barking up the wrong tree." – Mr. Duncan of Ohio in the United States House of Representatives, July 7: Congressional Globe, p. 474, Appendix.
 * 1839 – "The same reckless indifference which causes a puppy to bark up the wrong tree." – Chemung (NY) Democrat, September 18. 1839.