If on the trial of any action or proceeding brought under this chapter it is ascertained and adjudged by the judge of the district court that the livestock or animal taken up by the party complaining was not unlawfully at large upon the premises of another or upon the public lands, highways, roads or streets in the State of Alabama, he shall enter a judgment directing that such livestock or animal be discharged and taxing the party complaining with all the costs.