I got this error when the .java file was present outside the “src” folder. It got fixed after moving into the “src” folder.
Please see the picture.