In my case, everything is set up correctly (JDK, IntelliJ configuration), but I still encountered this error. However, after closing and reopening IntelliJ IDEA, the issue was resolved.