Focusing works by detecting contrast within your selected focus point, i.e. if you are using the centre focus point, then whatever you are pointing at has to have contrast. If you're pointing at a white wall or clear sky, the camera will not be able to figure out what is the distance between you and the object you are focusing at, and thus will not be able to focus.
Similarly, if it's dark, naturally the contrast between things is much lower. It then becomes difficult for the camera to pick out the contrast in order to focus.
The best thing to do is to (a) look for something with a high contrast to focus on (e.g. something lit by a lamppost) or (b) open your on camera flash and let the focus assist flash fire, then when it's focused, close the flash and take your photo