Android - Java HashMap keySet suddenly returns null -
i have 2 methods:
first 1 iterates on hashmap<string, string>
("mwidgetstartconfig") set values of spinner widgets in fragment. method called in onresume
.
the second method implements onitemselected
callback method of onitemselectedlistener
, updates values in hashmap<string, string>
("mwidgetcurrentconfig") according spinner item selected.
here methods:
protected void configurewidgets() { for(string tag : mwidgetstartconfig.keyset()) { int valueindex = mspinnervalues.indexof(mwidgetstartconfig.get(tag)); ((spinner) mlayout.findviewwithtag(tag)).setselection(valueindex); } } public void onitemselected(adapterview<?> parent, view v, int pos, long id) { string tag = (string) v.gettag(); string value = (string) parent.getitematposition(pos); mwidgetcurrentconfig.put(tag, value); }
the weird thing is, first method works fine long don't in second method (i.e. comment out body). in second method, nullpointerexception
in first method when called second time, string
"tag" being null (the first call works fine somehow).
i don't why happens, since don't access or change "mwidgetstartconfig" variable @ in second method. i've tried different ways iterate on hashmap
- same result.
any appreciated!
Comments
Post a Comment