I have had that happen to me as well. In my case, it was the hood. I hadn't closed it completely, and the right front corner was not quite latched down tight. Click the hood latch, slam the hood again (gently!), and try to lock the car.
If it is a door, hood or hatch switch that is preventing...