-1
I’m trying to compile a Helloworld class for testing, and it’s giving an error that I don’t know how to solve. Does anyone know a solution? From the looks of it, it’s some version-related problem.
I’m trying to compile it like this:
String arquivo2 = "/C:/classes/HelloWorld.java";
PrintWriter saida = new PrintWriter(new FileWriter("logCompilacao.txt"));
int resultadoCompilacao = com.sun.tools.javac.Main.compile(new String[]{arquivo2},saida);
But the result is this:
/C:/classes/HelloWorld.java:2: cannot access java.lang.Object
bad class file: C:\Program Files\Java\jre1.8.0_73\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 HelloWorld {
^
1 error
-----------class file has Wrong version 52.0, should be 49.0---------
How to fix it? What version problem is this?
Added: I executed java -version
and javac -version
and both returned 1.8.0_73
Trying to compile using different Java version. Just hang on, major version 49? This is Java 5, who even uses this o_0
– DH.
But my java is in the latest version. This would be a problem in the javac jar?
– Araújo Filho
No no, your Java is 52(Java 8), the source that was built with Java 5. You can see that the first Java folder that appears in your %PATH% and JAVA_HOME(if you have) is Java 8 as well.
– DH.
@DH. what do you mean by "first java folder of my "%PATH%?" If you are referring to the Path environment variable, it looks like this: C: Programdata Oracle Java javapath;;%JAVA_HOME% bin and my JAVA_HOME looks like this: C: Program Files Java jdk1.8.0_73
– Araújo Filho
@Araújofilho just a hint, constantly editing without adding anything in the question does not help much. Wait until someone can help you, editing costante makes it look like you are editing purposely so that it gains prominence.
– user28595
Got it. Thanks @Diegof
– Araújo Filho
Rotate the commands
java -version
andjavac -version
and add to the question, the problem may be different verses between jdk and jre.– user28595
There, I made this new edition to add the content to the question @Diegof
– Araújo Filho