How to fix this error: the class file has the wrong version 52.0, should be 49.0

I really struggle with that. I was not able to configure Intellij to use Javac, unable to start javadoc. I just can't seem to have my Java runtime stable and productive on Mac OSX.

I created the simplest example, which is the world hello program, and still errors from the command line. Everything I read about this error tells me to “update the compiler”. But I'm really not sure what the problem is: javac and java are running 1.8 (now, after I tried updating the JVM system).

I explicitly set the path when calling javac, checking version, etc. Everything tells me about it 1.8.

Can anyone explain how to fix this? (without returning my system to 1.5 SDK).

This is inferred from the main hello world application:

$JAVA_HOME/bin/javac Main.java
Main.java:3: cannot access java.lang.Object
bad class file: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 52.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class Main {
       ^
1 error
localhost:mycompany$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
localhost:mycompany$

Exiting javac version:

javac -version
javac 1.8.0_45
javac: no source files
Usage: javac <options> <source files>

Exiting java version:

java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
+4
source share
2 answers

The error message means that you are trying to load a Java 8 class with a Java 5 virtual machine.

For some unknown reason, it $JAVA_HOME/bin/javacuses Java runtime ( .../rt.jar) JDK 8 , but the compiler itself is loaded with the Java 5 virtual machine.

The next step would be to make sure that $JAVA_HOME/bin/javacin fact what should be (and not a script that does something strange). I would also check the environment ( CLASSPATH) and parameters like -Xbootclasspath. Try set | grep -i javaand set | grep -i pathlook for suspicious variables.

If nothing works, try installing the Java 8 SDK again.

+3

IDE Arduino ant. , tools.jar /Library/Java/Extensions/ - , .

+1

All Articles