You know the line and the error.
Quote:
postList!!.add(post!!)
You use
!!
operator.
!!
will throw
NullPointerException
if the value is null.
With
!!
, if
postList
is null OR
post
is null, it will raise the error.
Look at the reason, handle the same. Given you used operator !!, I am assuming you wrote it for a reason and want a
NullPointerException
to be raised. If you got this code from elsewhere and intention is to check for null, do that.
Reference:
Null Safety - Kotlin Programming Language[
^]
Quote:
the not-null assertion operator (!!) converts any value to a non-null type and throws an exception if the value is null. We can write b!!, and this will return a non-null value of b (e.g., a String in our example) or throw an NPE if b is null: val l = b!!.length