I solved this error on my mac m1 air just by adding the path of new jdk version in ~/.zshrc file.
export PATH="SPATH:/Users/ayushpattnaik/Documents/Deyeloper/flutter/bin" export JAVA_HOME=nibrary/Jaya/JayaVirtualMachines/openjdk-11.jdk/Contents/Home [ayushpattnaik@Ayushs—MacBook—Air ~ % java —version openjdk version "11.0.18" 2023-01-17 OpenJDK Runtime Environment Homebrew (build 11.0.18+0) OpenJDK 64—Bit Server VM Homebrew (build 11.0.18+0, mixed mode) I have multiple jdks in my /Library/Java/JavaVirtualMachines path. So I can choose any version I wish to set as my default java path.

