This error is coming because Xcode gets deleted, corrupt or moved. In my case I removed Xcode from my Mac and faced the same issue.
I fixed it by executing two simple steps:
Open Terminal
Simply run the following command
sudo xcode-select -r
sudo xcode-select -r
And now the error has been resolved.