2014-02-06 46 views
0
MyClass.java: 

package test; 
public class MyClass { 
public void myMethod(){ 
    System.out.println("My Method Called"); 
} 
} 

    Listing for SimpleCompileTest.java that compiles the MyClass.java file. 

    SimpleCompileTest.java: 

    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(); //Line 6 
    int compilationResult = compiler.run(null, null, null, fileToCompile); 
      if(compilationResult == 0){ 
     System.out.println("Compilation is successful"); 
    }else{ 
     System.out.println("Compilation Failed"); 
    } 
} 
} 

ERROR使用Java API來編寫

Error

我編譯SimpleCompileTest.java和收到此錯誤。幫幫我!!!

+0

你試過調試過嗎?您也可以提供代碼行號 - 堆棧跟蹤指向第6行。 – LastFreeNickname

+0

@LastFreeNickname完成 – rick

+0

可能的重複http://stackoverflow.com/questions/15513330/toolprovider-getsystemjavacompiler-returns-null-usable-with- only-jre-install –

回答

0

我不確定你的問題的正確答案是什麼,但你應該看看這個Example