Minecraft needs a certain Java version for each version of the game. If you do not have the correct version installed, Minecraft will not work.
Certain Minecraft versions need specific versions of Java. Below, is a table to help tell you which version you need and download links respectively.
|Minecraft Version||Java Version||Java Download Link|
|1.6 - 1.16||8||Java 8|
|1.18 - 1.19||17||Java 17|