且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决java.lang.NullPointerException错误?

更新时间:2023-11-19 13:53:10

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!