android - Getting null pointer exception on interface -
i wanna pass arraylist on class class extends listfragments.but whenever call getting null pointer exception.
async class
public class searchjobasync extends asynctask<string, string, string> { private string response; context c; searchmodel data; arraylist<searchmodel> values; getarraylist list; public interface getarraylist { public void getlist(arraylist<searchmodel> data); } public searchjobasync(context c, arraylist<searchmodel> values, getarraylist list) { this.c = c; this.values = values; this.list = list; } 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); } } 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; } }
listfragment class
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.execute (); searchjobasync = new searchjobasync (c, data, this); } @override public void getlist(arraylist<searchmodel> data) { customlist = new searchjobcustomlist (c, data); setlistadapter (customlist); } }
i m getting error on lines said logcat
list.getlist (values);
and
public class searchjobasync extends asynctask<string, string, string>
logcat
06-26 13:03:46.256 31713-31713/com.jobs_on_call_fragments e/androidruntime﹕ fatal exception: main 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)
other activity uses async
public class searchjobsfragment extends fragment implements view.onclicklistener { private view view; private spinner spcategory; private button btsearch; private spinner sptoyrs; private spinner spfrommonths; private spinner spfromyrs; private spinner sptomonths; private edittext etjobcode; private string[] yrsarray, montharray, professionarray; private arrayadapter<string> toyrs, tomonths, profession; private context c; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate (r.layout.search_jobs_frag, container, false); return view; } private void initialize() { c = getactivity (); spcategory = (spinner) getactivity ().findviewbyid (r.id.sp_category); btsearch = (button) getactivity ().findviewbyid (r.id.bt_search); sptoyrs = (spinner) getactivity ().findviewbyid (r.id.sp_to_yrs); spfrommonths = (spinner) getactivity ().findviewbyid (r.id.sp_from_months); spfromyrs = (spinner) getactivity ().findviewbyid (r.id.sp_from_yrs); sptomonths = (spinner) getactivity ().findviewbyid (r.id.sp_to_months); etjobcode = (edittext) getactivity ().findviewbyid (r.id.et_job_code); btsearch.setonclicklistener (this); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated (savedinstancestate); initialize (); spinnersetup (); } private void spinnersetup() { //for to/from yrs yrsarray = getresources ().getstringarray (r.array.experience_yrss); toyrs = new arrayadapter<string> (c, r.layout.spinner_textview, yrsarray); toyrs.setdropdownviewresource (android.r.layout.simple_list_item_single_choice); sptoyrs.setadapter (toyrs); spfromyrs.setadapter (toyrs); // to/from months montharray = getresources ().getstringarray (r.array.experience_months); tomonths = new arrayadapter<string> (c, r.layout.spinner_textview, montharray); tomonths.setdropdownviewresource (android.r.layout.simple_list_item_single_choice); sptomonths.setadapter (tomonths); spfrommonths.setadapter (tomonths); //for category professionarray = getresources ().getstringarray (r.array.profession); arrays.sort (professionarray, 1, professionarray.length); profession = new arrayadapter<string> (c, r.layout.spinner_textview, professionarray); profession.setdropdownviewresource (android.r.layout.simple_list_item_single_choice); spcategory.setadapter (profession); } @override public void onclick(view view) { searchjobasync searchjobasync = new searchjobasync (c); searchjobasync.execute (); } }
problem:
implements searchjobasync.getarraylist
you trying call interface on different class not static, thats why compiler having trouble find it
solution:
make getarraylist
static interface
static interface getarraylist { public void getlist(arraylist<searchmodel> data); }
edit:
if called other activity call null pointer check
sample:
if (values.size () > 0) { if(list != null) list.getlist (values); }
Comments
Post a Comment