-1

Possible Duplicate:
Null Pointer Exception while using Java Compiler API

I am having some issues with this program.

Error:

Exception in thread "main" 
java.lang.NullPointerException at test.SimpleCompileTest.main(SimpleCompileTest.java:9)

Program:

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 has failed");
        }
        }
    }
Community
  • 1
  • 1
Daro Royoss
  • 25
  • 1
  • 4

1 Answers1

0

Compilation of Java programmes is not that simple and needs a little bit more effort. Please take a look at the tutorials and API, e.g. http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html. According to your NPE, check http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html:

Unless explicitly allowed, all methods in this package might throw a NullPointerException if given a null argument or if given a list or collection containing null elements. Similarly, no method may return null unless explicitly allowed.

Christian Ullenboom
  • 1,388
  • 3
  • 24
  • 20