When I run my Java program, it gives me an error on this line
compiler.getTask(null, null, new DiagnosticCollector<JavaFileObject>(), null, null, compilationUnits);
Error I am getting is:
Exception in thread "main" java.lang.NullPointerException
at AnotherClassLoader.loadClass(test.java:58)
at test.main(test.java:30)
at Main.main(Main.java:68)
Can you please tell me how can I solve this error?
NullPointerExceptionoccurs. You just have to understand why you got that and fix it...someNullExpression.someMember. That is, thenullvalue must be the target expression of a member/method for this exception to naturally occur. In the posted example there is only one expression that can meet this requirement. (Hint: what does thecompilervariable evaluate to?)