android - Dynamic Grid View as Array -
hey guys building app show data grid view , grid view may multiple depend on web service data using dynamic grid view objects array when initializing grid view objects.. showing me compile time error(null pointer exception) 1 have answer question.
public class foodlevelpageone extends activity { private button home; private button back; private linearlayout linearlayout; private httpresponse httpresponse; ..... ... private arraylist<jsondata> al1[]; private gridview gv[]; .... .... .... protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate);` ... ... gv[i] = new gridview(getapplicationcontext());
you have not initialized , specified size of array.
you should follow these steps:
get size of response of webservice data, i.e. how many gridviews shown/filled.
jsonarray arrayfromwebservice = new jsonarray(webserviceresponse); int size_of_grid = arrayfromwebservice.length;
now, initialize grid array size_of_grid variable.
gv = new gridview[size_of_grid]; // work array.
Comments
Post a Comment