android - Get the data from array list from onPost execute method of async task -


i using asynck task json , parse it.the value of parsed json storing in arraylist. want want arraylist in different class.i have made method getlist() arraylist there getting null value

async class

    public class searchjobasync extends asynctask<string, string, string> {     private string response;     context c;     searchmodel data;     arraylist<searchmodel> values;     getarraylist list;      public searchjobasync(context c, getarraylist list) {         this.c = c;         this.list = list;     }      public interface getarraylist {         public void getlist(arraylist<searchmodel> data);      }      public searchjobasync(context c) {         this.c = c;     }      @override     protected void onpreexecute() {         super.onpreexecute ();         commonfunctions.showprogress (c, "please wait...", true);      }      @override     protected void onpostexecute(string s) {         values = new arraylist<searchmodel> ();          super.onpostexecute (s);         if (!s.trim ().contains ("table")) {             crouton.maketext ((android.app.activity) c, "nothing found", style.info).show ();         } else {             try {                  jsonobject jsonobject = new jsonobject (s);                 jsonobject newdataset = jsonobject.getjsonobject ("newdataset");                 if (newdataset.get ("table") instanceof jsonobject) {                     jsonobject table = newdataset.getjsonobject ("table");                     data = new searchmodel (table.getstring ("job_category"), table.getstring ("min_exp"), table.getstring ("max_exp"), table.getstring ("posted_on"), table.getstring ("candidate_counts"), table.getstring ("applications"), table.getstring ("no_of_pos"), table.getstring ("job_desc"), table.getstring ("job_type"), table.getstring ("job_hours"), table.getstring ("job_status"), table.getstring ("job_exp_date"), table.getstring ("address"), table.getstring ("gender_name"), table.getstring ("religion_name"), table.getstring ("exp_summary"), table.getstring ("ijob_request_id"), table.getstring ("requestor_name"));                     values.add (data);                 } else if (newdataset.get ("table") instanceof jsonarray) {                     jsonarray tablearray = newdataset.getjsonarray ("table");                      (int = 0; < tablearray.length (); i++) {                         jsonobject table = tablearray.getjsonobject (i);                         data = new searchmodel (table.getstring ("job_category"), table.getstring ("min_exp"), table.getstring ("max_exp"), table.getstring ("posted_on"), table.getstring ("candidate_counts"), table.getstring ("applications"), table.getstring ("no_of_pos"), table.getstring ("job_desc"), table.getstring ("job_type"), table.getstring ("job_hours"), table.getstring ("job_status"), table.getstring ("job_exp_date"), table.getstring ("address"), table.getstring ("gender_name"), table.getstring ("religion_name"), table.getstring ("exp_summary"), table.getstring ("ijob_request_id"), table.getstring ("requestor_name"));                         values.add (data);                      }                  }                 if (values.size () > 0) {                    list.getlist (values);                 } else {                  }               } catch (jsonexception e) {                 e.printstacktrace ();             }         }           commonfunctions.showprogress (c, "", false);         intent = new intent (c, searchjoblistactivity.class);         c.startactivity (i);     }      @override     protected string doinbackground(string... s) {         response = httprequest.post ("https://beta135.hamarisuraksha.com/web/webservice/hsjobservice.asmx/findjobforvendor").send ("vendor_ientity_code=" + "34588a34-e969-4723-84fe-e5409b66a5b7" + "&job_code=" + "&job_category=1" + "&exp_years_from=0" + "&exp_months_from=0" + "&exp_years_to=0" + "&exp_months_to=0").body ();         response = response.replaceall ("<[^>]*>", "").replaceall ("\n", "");         log.e ("search jobs", "" + response);         return response;     }      public arraylist<searchmodel> getlist() {         return values;     } }  

class m using interface

public class searchjoblist extends listfragment implements searchjobasync.getarraylist {     private view view;     private listview lvsearchjobs;     private arraylist<searchmodel> data;     searchjobcustomlist customlist;     searchjobasync searchjobasync;     private context c;      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view = inflater.inflate (r.layout.search_job_lists, container, false);         return view;     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated (savedinstancestate);         c = getactivity ();         lvsearchjobs = (listview) getactivity ().findviewbyid (android.r.id.list);         data = new arraylist<searchmodel> ();         searchjobasync = new searchjobasync (c, this);       }      @override     public void getlist(arraylist<searchmodel> data) {         customlist = new searchjobcustomlist (c, data);         setlistadapter (customlist);     } }  

logcat

 java.lang.nullpointerexception             @ com.jobs_on_call_fragments.asynctasks.searchjobasync.onpostexecute(searchjobasync.java:83)             @ com.jobs_on_call_fragments.asynctasks.searchjobasync.onpostexecute(searchjobasync.java:25)             @ android.os.asynctask.finish(asynctask.java:631)             @ android.os.asynctask.access$600(asynctask.java:177)             @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644)             @ android.os.handler.dispatchmessage(handler.java:99)             @ android.os.looper.loop(looper.java:213)             @ android.app.activitythread.main(activitythread.java:4787)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:511)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:789)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:556)             @ dalvik.system.nativestart.main(native method)  

now how arraylist????? getting arrylist making static ,bt not right way.so please me

i think trying value before doinbackground completes work. use boolean static flag in asynctask task , update in onpostexecute. before getting value check flag. simple workaround. else have use interface.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -