Sigmund Freud first hypothesized that dreams occur to preserve sleep. He thought people had dreams to preoccupy their minds and prevent them from waking up. However, most scientists find this to be untrue, because people dream throughout their sleep cycle. Freud also thought that dreams represent repressed ideas in the subconscious. For example, if a person harbors bad feelings towards a neighbor, then she might dream of getting into a fight with the neighbor.
Carl Jung presented another theory of the meaning of dreams. Jung, one of Freud's understudies, hypothesized that dreams represent parts of a person's psyche that are unexpressed during the waking hours. For example, if a person is extremely shy and timid, then he might dream that he is doing something that is very bold and outgoing in a dream. This reflects his desire to be more bold in real life.
Another theory on the meaning of dreams holds that dreams help us solve problems. Certain ideas or principles might be hard for us to accept in real life because they're controversial, uncomfortable or confusing. Some believe that dreams help resolve these issues by inventing novel and simple scenarios. For example, if a person wants to confront a teacher about a bad grade, then she might dream that she is confronting the teacher about unfair grading practices. The dreams don't always present a precise game plan for problem solving, but they encourage a method that person might try to use.
Activation theory posits that dreams don't mean anything. Activation theorists believe that dreams represent random nerve firings in the brain, and the cerebral cortex tries to synthesize these random signals into some sort of plot. So, your nerves might send signals about ice cream, traffic lights and tennis shoes, which would lead your cerebral cortex to create a story in which you eat ice cream that spills on your shoes underneath a traffic light.