Auto focus systems on most DSLRs work by sensing the difference in contrast between edges, even those that use Phase Detection Autofocus. But when there are no sharp edges or contrast, or when there is not enough light to detect the contrast, the lens's auto focus will keep searching for an edge and will not be able to focus, this known as 'hunting'.
For example, if you try to focus on a cloudless sky or on a solid coloured wall with no contrasting edges, the camera won't be able to acquire automatic focus because of lack of contrasting edges.
These sequence of photos were taken at Speakers Corner, Hyde Park in London, where on Sunday mornings anybody can literally get up on their 'Soup Boxes' and scream their opinions to the world!
In the shot above, had I tried to focus on the plain area of the Muslim ladies' bhurka, the lens would not have been able to lock focus, so I intentionally set the focus square partly on her face, bhurka nd background and got an instant focus lock.
Similarly in this shot I focused on the man's face, had I tried to focus on his jacket, I would have had a problem.