How to run this code using command prompt. it always show null pointer exception.
/*Program1.java*/
import javax.swing.JFrame;
public class Program1 {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setVisible(true);
}
}
/*Program2.java*/
import javax.tools.*;
public class Program2 {
public static void main(String[] args){
String fileToCompile = "Program1.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 failed");
}
}
}
and how to add the tools.jar in a classpath.