Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class version

Tags:

java

macos

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

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?

like image 732
Suraj K Thomas Avatar asked Dec 23 '13 11:12

Suraj K Thomas


People also ask

Could not find or load main class in Java?

The Java “Could not find or load main class” error is thrown when the JVM fails to find or load the main class while executing a program. It usually occurs when executing a Java program from the command line. The "Could not find or load main class" error occurs when the JVM fails to load the main class.

What is the meaning of this error could not find class name?

Error: Could not find or load main class ClassName. Error: Could not find or load main class ClassName. The error is mostly generated when we incorrectly specify the class name at run time of the program.

Why does the JVM fail to load the main class?

The error generates because the JVM fails to load the main class or package name. There are some other reasons that generate the same error, as follows: The class has been declared in the wrong package. Dependencies missing from the CLASSPATH.

What is class name error in JVM?

The error is mostly generated when we incorrectly specify the class name at run time of the program. The error generates because the JVM fails to load the main class or package name.


Video Answer


3 Answers

Try

 java -version

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

like image 147
Tim B Avatar answered Oct 30 '22 16:10

Tim B


java –version

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

like image 31
en-dash Avatar answered Oct 30 '22 15:10

en-dash


java -version is the command to check java version

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

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

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>javac -version javac 1.8.0_121

like image 26
user7798450 Avatar answered Oct 30 '22 15:10

user7798450