Most auto focus systems rely on contrast to archive focus Eg; If you focus on a blank wall the body will not be able to achieve focus consequently the body will drive the lens continually back and forth as it can not achieve focus, This is known as focal hunting.
If this occurs you can change the lens over to manual focus.
It may be fault with a lens: the auto focus sensor or motor may have failed. This will cause the lens focus system to drive to the incorrect position.
It may be fault with the camera: auto focus sensor or the auto focus sub-mirror may have failed. If the senor or mirror fail the camera can not determine point of focus.
Check the camera auto focus points the best point to use is center point.