java - Android NullPointerException on variable in instantiated class -
i have activity calls expandablelistview. vanilla setup:
activity->creates expandablelistviewadapter->draw it.
when getchildview called , tries reference variable set via listadapter's constructor receives npe.
so activitya->data gets set, sent arbitrarylistadapter. when childview method referenced , tries use datafromactivitya nullpointerexception. i'm not sure why, when verify datafromactivitya in adapter class, verifies correctly. when try reference in getchildview method npe shows up.
to explain example:
class activitya extends activity { private sparsearray<sparsearray<object>> data; private arbitrarylistadapter adapter; public void oncreate() { this.data = arbitraryfunctiontopopulatedatavariable(); // populates this.adapter = new arbitrarylistadapter(this, this.data); // other stuff this.adapter.notifydatasetchanged(); } // rest of activity here } /******************************/ class arbitrarylistadapter extends baseexpandablelistadapter { private sparsearray<sparsearray<object>> datafromactivitya; public arbitrarylistadapter(context context, sparsearray<sparsearray<object>> x) { this.datafromactivitya = x; // @ point variable set } public view getchildview(int group, int child, boolean last, view convertview, viewgroup parent) { // stuff // npe arises!!! for(int = 0;i< this.datafromactivitya.size();i++){ log.d(tag, "group: " + i); for(int j = 0; j<this.datafromactivitya.get(i).size();j++) { log.d(tag, "child: " + this.datafromactivitya.get(j).tostring()); } log.d(tag, "============================"); } // other stuff } // finish listadapter functions here }
sigh worlds worst developer. didn't see in onresume() of activity clearing list. how stupid i!?
Comments
Post a Comment