Oleg Siboglov
06/12/2020, 2:50 AMjava.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Number.floatValue()' on a null object reference
can occur while iterating over a MutableList<Float
. All Float
values that are added to the list are nonNull
; a Float
value is returned from one function (where the return type is Float
), used by a different function (where the parameter type is Float
), and then added to the MutableList<Float>
. Later I iterate over the list ( for (i in 0 until list.size) list[i]
) and it is here when the exception is thrown, when I’m getting the values from the list. I’ve only ever seen this happen once from crashlytics, but I cannot understand how it even happened once. Values are only added to the list at one point in my execution. After adding values to the list, and before iterating over the list, I may remove the last value in the list ( list.removeAt(list.size - 1)
). Looking at the decompiled code ( ((Number)this.list.get(index)).floatValue()
) tells me that the value at that index is null. Am I misunderstanding the stack trace? Could someone please clear this up for me?Zach Klippenstein (he/him) [MOD]
06/12/2020, 3:01 AMJakub Pi
06/12/2020, 3:09 AME.Kisaragi
06/13/2020, 1:21 PM