I got this error when I started gradlew ktlintFormat in the Terminal of Arctic Fox build.
I opened Project Structure (menu File → Project Structure) and selected Java 11, but it didn't help even after a restart of Android Studio.
Then I changed the Java path in Settings (see the accepted answer), but it didn't help. You should set it.
I tried to change Windows system variables and changed
JAVA_HOME.(A short way: run
cmdwith administrative rights and write:setx /M JAVA_HOME "C:\Program Files\Java\jdk-11.0.11", and then restart Android Studio)Press Win+X, press "System", and enter "va".
I pressed Edit button and "Browse Directory...", and then selected JRE (or JDK) folder (without
bin) of Java 11. Then OK, and OK (as always).I opened
cmd(command line in Windows) and typed:%JAVA_HOME%. It wrote me this error:'C:\Program' is not recognized as an internal or external command, operable program or batch file.
Looking at Setting the JAVA_HOME Variable in Windows, I found that we should replace
Program FileswithProgra~1(yes, this DOS trick still works). So, replace JAVA_HOME again like in the picture below (C:\Progra~1\Android\Androi~1\jre).Restart Android Studio or reset the computer.




