0

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.

Java Coder
  • 60
  • 9
  • Use full path to Foo.java or place it where classes are outputed. Most likely built main class can't access Foo.java using relative path – Filip Bulovic Jun 21 '15 at 03:18
  • Hi Thanks, I used /Ibcs/src/com/coderbd/compile/Foo.java and compile/Foo.java respectively, but same error. – Java Coder Jun 23 '15 at 06:25
  • I removed package spec from code outputed it to file `cat > JDK6FirstCompile.java` compiled from terminal and successfully executed. That /Ibcs/src/... is it in your root folder? If it is relative path then Ibcs/src/... – Filip Bulovic Jun 23 '15 at 12:09

0 Answers0