如何解决 java.lang.NullPointerException 错误? [英] How to solve java.lang.NullPointerException error?
问题描述
当我运行我的 Java 程序时,它在这一行给我一个错误
When I run my Java program, it gives me an error on this line
compiler.getTask(null, null, new DiagnosticCollector
我得到的错误是:
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 方法期望的不是空值,但您传递的是空值.弄清楚 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 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!