错误: 无法创建 Java 虚拟机错误: 发生致命异常。程序将退出

我刚刚在我的64位 Windows-10操作系统上安装了 JavaSE 开发工具包8u91。我设置了 路径变量。我在命令提示符中尝试了 Java 版本,它给了我一个错误。

c:\Users\Onlymanu>java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

但是当我尝试 Java-version的时候,它起作用了。

我试过初始化 选项环境变量,也试过重新安装,但都不管用。有人能帮帮我吗?

265457 次浏览

Try executing below command,

java -help

It gives option as,

-version print product version and exit

java -version is the correct command to execute

I think you have put command like java -VERSION. This is in capital letters You need to put all command in lowercase letters

javac -version
java -version

All characters must be in lowercase letter

Your command is wrong.

Linux

java -- version

macOS

java -version

You can't use those commands other way around.

the command should be java -version

java -version
java -showversion

Both commands work In Linux 16.04 LTS

--version is a valid option from JDK 9 and it is not a valid option until JDK 8 hence you get the below:

Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

You can try installing JDK 9 or any version later and check for java --version it will work.

Alternately, from the installed JDK 9 or later versions you can see from java -help the below two options will be available:

    -version      print product version to the error stream and exit
--version     print product version to the output stream and exit

where as in JDK 8 you will only have below when you execute java -help

    -version      print product version and exit


I hope it answers your question.

I was facing a similar issue. Actually the command is :

java -version and not java --version.

You will get output something like this:

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

Java 8:

java -version

Java 9+:

java --version

This happens because the CMD doesn't recognize the "java --version" try writing "java -version" when "java --version" it tries to create a JVM. IT Fails because that's wrong command.

enter image description here