问题描述
当我运行我的Java程序时,它在这一行上给我一个错误
When I run my Java program, it gives me an error on this line
compiler.getTask(null,null,new DiagnosticCollector< JavaFileObject>(),null,null,compilationUnits);
我得到的错误是:
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?
推荐答案
NullPointerException表示你传递的其中一个变量为null,但是代码试图使用它,就像它不是。
A NullPointerException means that one of the variables you are passing is null, but the code tries to use it like it is not.
例如,如果我这样做:
Integer myInteger = null;
int n = myInteger.intValue();
代码尝试获取myInteger的intValue,但由于它为null,因此它没有:发生空指针异常。
The code tries to grab the intValue of myInteger, but since it is null, it does not have one: a null pointer exception happens.
这意味着你的getTask方法期望某些东西不是null,但你传递的是null。弄清楚getTask需要什么并传递它想要的东西!
What this means is that your getTask method is expecting something that is not a null, but you are passing a null. Figure out what getTask needs and pass what it wants!
这篇关于如何解决java.lang.NullPointerException错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!