Java 错误:无法找到或加载主类版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20742229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:59:54  来源:igfitidea点击:

Error: Could not find or load main class version

javamacos

提问by Suraj K Thomas

I have downloaded Java on mac mavericks system. But when I type on terminal to see the Java version using command:

我已经在 mac Mavericks 系统上下载了 Java。但是当我在终端上输入以使用命令查看 Java 版本时:

java version

I get the following error

我收到以下错误

Could not find or load main class version

无法找到或加载主类版本

I went to oracle website and tried a check to see if Java is installed on my system,which confirmed the Java7 is installed on the system. But why can I not see version in terminal?

我去了oracle网站并尝试检查我的系统上是否安装了Java,确认系统上安装了Java7。但是为什么我在终端中看不到版本?

采纳答案by Tim B

Try

尝试

 java -version

Without the minus sign it is trying to load a program called version.

如果没有减号,它会尝试加载一个名为 version 的程序。

回答by en-dash

java –version

will cause the same error (copied from webpage) as "–" is an em dash

将导致相同的错误(从网页复制),因为“–”是一个破折号

回答by user7798450

java -version is the command to check java version

java -version 是检查java版本的命令

Download latest Java SE from Oracle site and install it. Then reopen cmd and check java version using java -version.

从 Oracle 站点下载最新的 Java SE 并安装它。然后重新打开 cmd 并使用 java -version 检查 java 版本。

Set the Java path to bin and check it's version also. Both java and javac should be on same version.

将 Java 路径设置为 bin 并检查它的版本。java 和 javac 应该在同一版本上。

In my case:

就我而言:

C:\Users\darshan>java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

C:\Users\darshan>java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM(build 25.121-b13,混合模式)

C:\Users\darshan>javac -version javac 1.8.0_121

C:\Users\darshan>javac -version javac 1.8.0_121