以下是用eclipse ide编写的Java代码...
package compile;
import java.io.IOException;
import java.util.Arrays;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class Execute {
public static void main(String args[]) throws IOException, ClassNotFoundException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(
diagnostics, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager
.getJavaFileObjectsFromStrings(Arrays
.asList("F:\\practice java\\project\\KeepingMoreKidsQuiet.java"));
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager,
diagnostics, null, null, compilationUnits);
boolean success = task.call();
System.out.println(success);
if(!success)
System.out.println(diagnostics.getDiagnostics());
fileManager.close();
}
}
当我运行我的 Java 程序时,它在这一行给我一个错误
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
我得到的错误是:
compile.Execute.main(Execute.java:17) 处的线程“main”java.lang.NullPointerException 中的异常
你能告诉我如何解决这个错误吗?