android - Passing data from onPostExecute() to adapter -
can't pass data onpostexecute()
adapter autocomletetextview
. logcat shows me:
an exception occurred during performfiltering()! java.lang.nullpointerexception: collection == null.
public class uzactivity extends activity { private static final string debug_tag = "httpexample"; list<string> responselist; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_uz); final string url = "http://booking.uz.gov.ua/purchase/station/%d0%9a%d0%b8%d0%b5/"; new fetchstationtask().execute(url); autocompletetextview textview = (autocompletetextview) findviewbyid(r.id.autocompletetextview1); arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_dropdown_item_1line, responselist); textview.setadapter(adapter); } private class fetchstationtask extends asynctask<string, void, string>{ @override protected string doinbackground(string... urls) { try { return new uzfetcher().geturlstring(urls[0]); } catch (ioexception e) { return "unable retrieve web page. url may invalid."; } } @override protected void onpostexecute(string result){ try { objectmapper objectmapper = new objectmapper(); objectmapper.configure(deserializationfeature.fail_on_unknown_properties, false); stationresponse st = objectmapper.readvalue(result, stationresponse.class); responselist = new arraylist<>(); (int = 0; i<st.mstations.size(); i++){ responselist.add(st.mstations.get(i).gettitle()); } log.i(debug_tag, responselist.get(0)); } catch (ioexception e) { e.printstacktrace(); } log.i(debug_tag, result); } }
java.lang.nullpointerexception: collection == null.
arraylist
should initialized first.
just add,
responselist = new arraylist<string>();
after setcontentview();
Comments
Post a Comment