Hello!
Humor is a mental contrast between something that makes sense and something that does not. Three elements are needed: the nonsensical element, the corresponding "sensical" element, and the connection between the two.
Example 1:
Q. Why did the little boy throw the clock out the window?
A. He wanted to see time fly.
"Sensical" element: "Time fly" as a metaphor for the sense of time moving quickly.
Nonsensical element: "Time fly" in a literal sense, with "time" meaning a clock.
The connection between the two: two interpretations of the same phrase.
Example 2:
Q: Why did the farmer go to town?
A: Fireplace.
While the answer certainly is nonsensical, there is no corresponding "sensical" element, and therefore there is no perception of humor. Another way of looking at this: A typical sensical answer of "To buy groceries" has no connection to the given nonsensical element, and therefore the humor fails. If it indeed was such an attempt.
I presented a paper and a workshop on this topic at the Texas Objectivist Societies Conference in 1993 (?). I'd always wanted to give the topic a more scholarly polish; perhaps it's getting to be that time. =)