java - Android Hashmap returning null -
i have expandable listview data stored in
hashmap<integer, list<mychildobject>>
and when expanding crashes saying list.size()
null pointer in adapter.getchildrencount()
simply:
public int getchildrencount(int groupposition) { return mmap.get(groupposition).size(); }
now put break point in ran debugger , saw mmap
fine, i'm testing 1 element list of element contains 1 child object. can see in debugger element in fact list size = 1.
but testing list<mychildobject> list = mmap.get(0);
returns null when can see in debugger mmap has element (<integer.valueof(0), non null list of objects>
).
whats weirder when testing 4 hashmap elements:
<0, list> <1, list> <2, list> <3, list>
it works fine , i'm able access non null list calling mmap.get(n)...
am not using hashmap
correctly here integer keys? why unable retrieve elements?
odds pretty it's checking integer object boxes , unboxes correctly values between -128 , 127, because typically these saved. but, equals between these should same both given key value integer check underlying value rather memory location.
why using hashmap? mean doesn't form call out arraylist<arraylist<mychildobject> >
? , in case, should switch count function have null check anyhow.
public int getchildrencount(int groupposition) { list<mychildobject> list = mmap.get(groupposition); if (list == null) return 0; return list.size(); }
because odds if allow in 0 sized objects, you're off using null.
Comments
Post a Comment