title: Null Pointer Exception while using Java Compiler API
body: <p>MyClass.java:</p>
  
  <pre><code>package test;
  public class MyClass {
      public void myMethod(){
          System.out.println("My Method Called");
      }
  }
  </code></pre>
  
  <p>Listing for SimpleCompileTest.java that compiles the MyClass.java file.</p>
  
  <p>SimpleCompileTest.java:</p>
  
  <pre><code>package test;
  import javax.tools.*;
  public class SimpleCompileTest {
      public static void main(String[] args) {
  String fileToCompile = "test" + java.io.File.separator +"MyClass.java";
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  int compilationResult = compiler.run(null, null, null, fileToCompile);
          if(compilationResult == 0){
              System.out.println("Compilation is successful");
          }else{
              System.out.println("Compilation Failed");
          }
      }
  }
  </code></pre>
  
  <p>I am executing the SimpleCompileTest class and getting a NullPointerException. The ToolProvider.getSystemJavaCompiler() is returning null. Can someone tell me what is wrong with the code</p>