I am trying to compile a simple java class using JavaCompiler class, but I see following errors: Exception in thread "main" java.lang.NullPointerException at com.coderbd.compile.JDK6FirstCompile.main(JDK6FirstCompile.java:12)
I am using JDK 1.8.31, Please help me to solve the issue. Coder Is here:
package com.coderbd.compile;
import java.io.IOException;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class JDK6FirstCompile {
public static void main(String args[]) throws IOException, NullPointerException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int results = compiler.run(null, null, null, "Foo.java");
System.out.println("Success: " + (results == 0));
}
}
// File: Foo.java
class Foo {
public static void main(String args[]) {
System.out.println("Hello, World");
}
}
Any help will be appreciated.