Guest User

Untitled

a guest
Aug 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Java Compiler API NullPointerException
  2. +---- src
  3. +----- package
  4. +------ Compile.java
  5. +
  6. +
  7. +---- temp
  8. +----- anotherpackage
  9. +------ Temp.java (file to compile)
  10.  
  11. public static void compile(URI path, InputStream is, OutputStream os, OutputStream err) throws IOException {
  12. SimpleJavaFileObject source = new CustomJavaFileObject(path, Kind.SOURCE);
  13. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  14. JavaCompiler.CompilationTask task = compiler.getTask(new PrintWriter(err), null, null, null, null, Arrays.asList(source));
  15. task.call();
  16. }
  17.  
  18. class CustomJavaFileObject extends SimpleJavaFileObject {
  19. protected CustomJavaFileObject(URI uri, Kind kind) {
  20. super(uri, kind);
  21. }
  22. }
  23.  
  24. java.lang.NullPointerException
  25. at package.Compiler.compile(Compiler.java:20)
  26. at package.Interactive.main(Interactive.java:19)
  27.  
  28. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
Add Comment
Please, Sign In to add comment