A loose fit on the lens mount to the camera can sometimes cause this. Even if you hear the bayonet "click," it's still possible that the electronic contacts are intermittent. This happens every so often when I deal with certain third-party Teleconverters. I find that twisting just a little bit more in the mounting direction clears that error. Unfortunately, that really requires a mechanical (i.e., shop) fix because it can happen at any time.