Andrew Ebling
01/20/2021, 4:33 PMvar array = SparseArray<ByteArray>(1)
...array ends up being empty (it shows as “null”
in the debugger, and if I do this:
array.setValueAt(0, byteArrayOf(byte)
val value = array.get(0)
...then value
is null.
mkrussel
01/20/2021, 4:43 PMAndrew Ebling
01/20/2021, 4:44 PMget()
still returns null
Andrew Ebling
01/20/2021, 4:46 PMarray.size()
returns zero, even after the setValue()
mkrussel
01/20/2021, 4:47 PMsize
is 0
still since the array is empty. From documentation for setValue
For indices outside of the range 0...size()-1, the behavior is undefined for apps targeting Build.VERSION_CODES.P and earlier, and an ArrayIndexOutOfBoundsException is thrown for apps targeting Build.VERSION_CODES.Q and later.
I'm guessing you want to use the put
method.Andrew Ebling
01/20/2021, 4:49 PMput
unfortunatelymkrussel
01/20/2021, 4:51 PMsetValueAt
to put
should do what you want from reading the documentationAndrew Ebling
01/20/2021, 4:56 PMSparseArray
with it’s contents already in place?Andrew Ebling
01/20/2021, 4:56 PMAndrew Ebling
01/20/2021, 4:57 PMSpareArray
s unfortunatelymkrussel
01/20/2021, 4:59 PMtest
or androidTest
. If running in test
then that is because a fake version of SparseArray
is being used and default values are returned for everything. You will have to mock the SparseArray
also.Andrew Ebling
01/20/2021, 5:09 PMAndrew Ebling
01/20/2021, 5:15 PMAndrew Ebling
01/20/2021, 5:19 PMgildor
01/20/2021, 11:37 PMgildor
01/20/2021, 11:39 PM