java - Getting null while using interface method -


i have created async task background task.in async task class have made interface method finish.it used let me noe background task over.but when ever using interface getting null

async class

 public static class searchjobsasync extends asynctask<string, string, string> {             string response;             boolean value;             context c;             finished finished;              public searchjobsasync(context c, searchjobsasync.finished finished,boolean value) {                 this.c = c;                 this.finished = finished;                 this.value=value;              }              public static interface finished {                 void finish(boolean finish);             }              searchjobsasync(context c, boolean value) {                 this.value = value;                 this.c = c;               }              @override             protected string doinbackground(string... strings) {                 if (spyears.getselecteditemposition () == 0 && spmonths.getselecteditemposition () == 0 && sptoyears.getselecteditemposition () == 0 && sptomonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=0" + "&exp_months_from=0" + "&exp_years_to=99" + "&exp_months_to=99").body ();                 } else if (spyears.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=0" + "&exp_months_from=" + strmnths + "&exp_years_to=" + strtoyrs + "&exp_months_to=" + strtomnths).body ();                 } else if (spmonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=" + stryrs + "&exp_months_from=0" + "&exp_years_to=" + strtoyrs + "&exp_months_to=" + strtomnths).body ();                 } else if (spyears.getselecteditemposition () == 0 && spmonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=0" + "&exp_months_from=0" + "&exp_years_to=" + strtoyrs + "&exp_months_to=" + strtomnths).body ();                 } else if (sptoyears.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=" + stryrs + "&exp_months_from=" + strmnths + "&exp_years_to=25" + "&exp_months_to=" + strtomnths).body ();                 } else if (sptomonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=" + stryrs + "&exp_months_from=" + strmnths + "&exp_years_to=" + strtoyrs + "&exp_months_to=25").body ();                 } else if (sptoyears.getselecteditemposition () == 0 && sptomonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=" + stryrs + "&exp_months_from=" + strmnths + "&exp_years_to=25" + "&exp_months_to=25").body ();                 } else if (spyears.getselecteditemposition () == 0 && spmonths.getselecteditemposition () == 0 && sptoyears.getselecteditemposition () == 0 && sptomonths.getselecteditemposition () == 0) {                     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=" + strcategory + "&exp_years_from=0" + "&exp_months_from=0" + "&exp_years_to=25" + "&exp_months_to=25").body ();                 } else {                     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=" + strcategory + "&exp_years_from=" + stryrs + "&exp_months_from=" + strmnths + "&exp_years_to=" + strtoyrs + "&exp_months_to=" + strtomnths).body ();                  }                 //vendor_ientity_code=string&job_code=string&job_category=string&exp_years_from=string&exp_months_from=string&exp_years_to=string&exp_months_to=string                 response = response.replaceall ("<[^>]*>", "").replaceall ("\n", "");                 log.e (" search job response", "" + response);                 return response;              }              @override             protected void onpreexecute() {                 super.onpreexecute ();     //            commonfunctions cs = new commonfunctions ();     //            cs.showprogressbar (c, true);                 pdialog = new progressdialog (c);                 pdialog.setmessage ("please wait...");                 pdialog.setcancelable (false);                 pdialog.show ();             }              @override             protected void onpostexecute(string s) {                 super.onpostexecute (s);                 arraylist = new arraylist<hashmap<string, string>> ();                 try {                     jsonobject = new jsonobject (s);                     newdataset = jsonobject.getjsonobject ("newdataset");                     if (newdataset == null) {                         toast.maketext (c, "error", toast.length_short).show ();                     } else if (newdataset.get ("table") instanceof jsonobject) {                         hashmap<string, string> map = new hashmap<string, string> ();                         jsonobject table = newdataset.getjsonobject ("table");                          map.put ("category", table.getstring ("job_category"));                         map.put ("minexp", table.getstring ("min_exp"));                         map.put ("maxexp", table.getstring ("max_exp"));                         map.put ("postedon", table.getstring ("posted_on"));                         map.put ("counts", table.getstring ("candidate_counts"));                         map.put ("applied", table.getstring ("applications"));                         map.put ("position", table.getstring ("no_of_pos"));                         map.put ("desc", table.getstring ("job_desc"));                         map.put ("type", table.getstring ("job_type"));                         map.put ("hours", table.getstring ("job_hours"));                         map.put ("status", table.getstring ("job_status"));                         map.put ("expirydate", table.getstring ("job_exp_date"));                         map.put ("address", table.getstring ("address"));                         map.put ("state", table.getstring ("job_state"));                         map.put ("country", table.getstring ("job_country"));                         map.put ("city", table.getstring ("job_city"));                         map.put ("gender", table.getstring ("gender_name"));                         map.put ("religion", table.getstring ("religion_name"));                         map.put ("summary", table.getstring ("exp_summary"));                         map.put ("requestid", table.getstring ("ijob_request_id"));                         map.put ("requestorname", table.getstring ("requestor_name"));     //                    map.put ("requestid",table.getstring ("ijob_request_id"));                           arraylist.add (map);                       } else if (newdataset.get ("table") instanceof jsonarray) {                          jsonarray tablearray = newdataset.getjsonarray ("table");                          (int = 0; < tablearray.length (); i++) {                             hashmap<string, string> map = new hashmap<string, string> ();                              jsonobject table = tablearray.getjsonobject (i);                              map.put ("code", table.getstring ("job_code"));                             map.put ("category", table.getstring ("job_category"));                             map.put ("minexp", table.getstring ("min_exp"));                             map.put ("maxexp", table.getstring ("max_exp"));                             map.put ("postedon", table.getstring ("posted_on"));                             map.put ("counts", table.getstring ("candidate_counts"));                             map.put ("applied", table.getstring ("applications"));                             map.put ("position", table.getstring ("no_of_pos"));                             map.put ("desc", table.getstring ("job_desc"));                             map.put ("type", table.getstring ("job_type"));                             map.put ("hours", table.getstring ("job_hours"));                             map.put ("status", table.getstring ("job_status"));                             map.put ("expirydate", table.getstring ("job_exp_date"));                             map.put ("address", table.getstring ("address"));                             map.put ("state", table.getstring ("job_state"));                             map.put ("country", table.getstring ("job_country"));                             map.put ("city", table.getstring ("job_city"));                             map.put ("gender", table.getstring ("gender_name"));                             map.put ("religion", table.getstring ("religion_name"));                             map.put ("summary", table.getstring ("exp_summary"));                             map.put ("requestid", table.getstring ("ijob_request_id"));                             map.put ("requestorname", table.getstring ("requestor_name"));                               arraylist.add (map);     //                        add.add (values);                           }                       }                 } catch (jsonexception e) {                     e.printstacktrace ();                 }                 if (value) {                     finished.finish (true);                     intent = new intent (c, searchjobslist.class);                     c.startactivity (i);                 }                 if (pdialog.isshowing ()) {                     pdialog.dismiss ();                 }              }         }          @override         public void onbackpressed() {             super.onbackpressed ();             intent = new intent (c, home.class);             startactivity (i);         }     } 

logcat

06-27 17:14:30.406  11554-11554/com.example.jobs_on_call.app e/androidruntime﹕ fatal exception: main     java.lang.nullpointerexception             @ com.example.jobs_on_call_search_jobs.searchjobs$searchjobsasync.onpostexecute(searchjobs.java:334)             @ com.example.jobs_on_call_search_jobs.searchjobs$searchjobsasync.onpostexecute(searchjobs.java:160)             @ 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) 

// try below code. make single constructor.

//interface code is:

 public interface webservicelistener {   // ever want use arraylist or map.  public void onactioncomplete (arraylist<string> _arralist);       public void onactioncompletes (hashmap<string, string> _map);     } 

//your async class

 public class searchjobsasync extends asynctask<string, string, string> {      webservicelistener _object = null;     context _ctx;     public searchjobsasync(context _ctx,webservicelistener object) {     this._ctx = _ctx;     this._object = object; }  @override protected string doinbackground(string... params) {     string _data = null;     try {         // stuff     } catch (exception e) {         e.printstacktrace();     }      return _data; }  @override protected void onpostexecute(string result) {     super.onpostexecute(result);         hashmap<string, string> map = new hashmap<string,string>();     map.put("key", result);     object.onactioncompletes(map);     _arraylist.add(result);     object.onactioncomplete(_arraylist); }  } 

// in yiour main activity want data make object of async class , pass parameters like:

  searchjobsasync   _parse = new searchjobsasync(_ctx,this); 

// inplement methods of interface , data like:

@override public void onactioncomplete(arraylist<string> _array) {     string _mydata = _array.get(0);     system.out.println("hhhh" + _mydata);  }  @override public void onactioncompletes(hashmap<string, string> _map) {     string _mydatas = _map.get("pankaj");     system.out.println("thakur shab" + _mydatas);  } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -