I'm trying to compile a HelloWorld class for testing, and it's giving an error that I do not know how to solve. Does anyone know a solution? It looks like it's some version-related issues.
I'm trying to compile 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 solve it? What version problem is this?
Added: I executed java -version
and javac -version
and both returned 1.8.0_73