I was using the Intellij for the first time and this error spilled up.
On File > Project Structure, under Project, the projectSDK had JDK21
Still got this error
I did 2 things
Under File > Invalidate Cache, Invalidate and restart
Then used "Add JDK from Disk" option to load the JDK from JavaVirtualMachines/jdk-21.jdk/Contens/Home
It works