If you are using Intellij and the above solutions are not working try: File > Invalidate Caches / Restart
This worked for me. Sometimes when you are working through multiple branches, the IDE uses its cache and cannot find the file in the cache hence it shows error during compilation.