android - Adapter nullpointexception when reload listview -
i spend 3 days on bug still can't why happen.
in fragment oncreateview
call asynctask:
new getacceptedmeetings().execute();
getacceptedmeetings:
private class getacceptedmeetings extends asynctask<string, string, string> { int shortanimtime = getresources().getinteger( android.r.integer.config_shortanimtime); @override protected void onpreexecute() { super.onpreexecute(); acceptedlv.setvisibility(view.gone); loadstatusview.setvisibility(view.visible); loadstatusview.animate().setduration(shortanimtime) .setlistener(new animatorlisteneradapter() { @override public void onanimationend(animator animation) { loadstatusview.setvisibility(view.visible); } }); } @override protected string doinbackground(string... params) { list<namevaluepair> meetingparams = new arraylist<namevaluepair>(); meetingparams.add(new basicnamevaluepair("attendant[user_id]", userid)); // getting json string url jsonobject meetingjson = jparser.makehttprequest( str_url_getmeeting, "post", meetingparams); // check log cat json response log.d("user's meeting: ", meetingjson.tostring()); try { if (meetingjson.getint("msg") == 1) { jsonarray meetings = meetingjson.getjsonarray("meeting"); arrmeetings.clear(); (int = 0; < meetings.length(); i++) { jsonobject c = meetings.getjsonobject(i); string strrole = c.getstring("role_id"); if (strrole.equals("1")) { string strid = c.getstring(mttag_meetingid); string strname = c.getstring(mttag_meetingname); string strcontent = c.getstring(mttag_content); string[] strdatetime = c.getstring(mttag_date) .split("t"); string strduration = c.getstring(mttag_duration); string strlocation = c.getstring(mttag_location); string strcoordinate = c .getstring(mttag_coordinate); hashmap<string, string> map = new hashmap<string, string>(); map.put(mttag_meetingid, strid); map.put(mttag_meetingname, strname); map.put(mttag_content, strcontent); map.put(mttag_date, strdatetime[0]); map.put(mttag_time, strdatetime[1].substring(0, strdatetime[1].length() - 5)); map.put(mttag_duration, strduration); map.put(mttag_location, strlocation); map.put(mttag_coordinate, strcoordinate); calendar cal = calendar.getinstance(); simpledateformat df = new simpledateformat( "yyyy-mm-dd"); string formatteddate = df.format(cal.gettime()); date inputdate = df.parse(strdatetime[0]); log.d("date", inputdate.tostring()); date currentdate = df.parse(formatteddate); string status = ""; if (inputdate.compareto(currentdate) == 0){ if(inputdate.before(currentdate)) status = "today"; else if(inputdate.after(currentdate)) status = "done"; } else if (inputdate.compareto(currentdate) < 0) status = "done"; else if (inputdate.compareto(currentdate) > 0) status = "incoming"; map.put(mttag_meetingstatus, status); arrmeetings.add(map); } } log.d("arrmeetings: ", arrmeetings.tostring()); } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { loadstatusview.setvisibility(view.gone); adapter = new simpleadapter( // updating listview getactivity(), arrmeetings, r.layout.meeting_item, new string[] { mttag_meetingname, mttag_date, mttag_time, mttag_location, mttag_meetingstatus }, new int[] { r.id.txttitlemeeting, r.id.txtdatetime, r.id.txttime, r.id.txtlocation, r.id.txtstatusmeeting }) { @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; (int = 0; < arrmeetings.size(); i++) { layoutinflater vi = (layoutinflater) getactivity() .getsystemservice(context.layout_inflater_service); v = vi.inflate(r.layout.meeting_item, null); textview txttitlemeeting = (textview) v .findviewbyid(r.id.txttitlemeeting); textview txtdatetime = (textview) v .findviewbyid(r.id.txtdatetime); textview txttime = (textview) v .findviewbyid(r.id.txttime); textview txtlocation = (textview) v .findviewbyid(r.id.txtlocation); textview txtstatusmeeting = (textview) v .findviewbyid(r.id.txtstatusmeeting); txttitlemeeting.settext(arrmeetings.get(position).get( mttag_meetingname)); txtdatetime.settext(arrmeetings.get(position).get( mttag_date)); txttime.settext(arrmeetings.get(position).get( mttag_time)); txtlocation.settext(arrmeetings.get(position).get( mttag_location)); if (arrmeetings.get(position).get(mttag_meetingstatus) .equals("today")) { txtstatusmeeting.settext(arrmeetings.get(position) .get(mttag_meetingstatus)); txtstatusmeeting.settextcolor(getactivity() .getresources().getcolor(r.color.today)); } else if (arrmeetings.get(position) .get(mttag_meetingstatus).equals("incoming")) { txtstatusmeeting.settext(arrmeetings.get(position) .get(mttag_meetingstatus)); txtstatusmeeting.settextcolor(getactivity() .getresources().getcolor(r.color.incoming)); } else if (arrmeetings.get(position) .get(mttag_meetingstatus).equals("done")) { txtstatusmeeting.settext(arrmeetings.get(position) .get(mttag_meetingstatus)); txtstatusmeeting.settextcolor(getactivity() .getresources().getcolor(r.color.done)); } } return v; } }; log.d("arrmeeting onpost:", arrmeetings.tostring()); if (adapter.isempty()) { txtnomeeting.sethint("you have no meeting created"); } else txtnomeeting.setvisibility(view.gone); acceptedlv.setadapter(adapter); acceptedlv.setvisibility(view.visible); acceptedlv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view v, int position, long id) { //code click event here }); } }
in first time call tab it's run good. when reload got error nullpointexception @ adapter = new simpleadapter
this logcat show
05-17 11:13:24.053: w/dalvikvm(4284): threadid=1: thread exiting uncaught exception (group=0xa4b7d648) 05-17 11:13:24.053: e/androidruntime(4284): fatal exception: main 05-17 11:13:24.053: e/androidruntime(4284): java.lang.nullpointerexception 05-17 11:13:24.053: e/androidruntime(4284): @ android.widget.simpleadapter.<init>(simpleadapter.java:85) 05-17 11:13:24.053: e/androidruntime(4284): @ info.android.mh.fragment.tabview_accepted_meeting_fragment$getacceptedmeetings$2.<init>(tabview_accepted_meeting_fragment.java:234) 05-17 11:13:24.053: e/androidruntime(4284): @ info.android.mh.fragment.tabview_accepted_meeting_fragment$getacceptedmeetings.onpostexecute(tabview_accepted_meeting_fragment.java:243) 05-17 11:13:24.053: e/androidruntime(4284): @ info.android.mh.fragment.tabview_accepted_meeting_fragment$getacceptedmeetings.onpostexecute(tabview_accepted_meeting_fragment.java:1) 05-17 11:13:24.053: e/androidruntime(4284): @ android.os.asynctask.finish(asynctask.java:631) 05-17 11:13:24.053: e/androidruntime(4284): @ android.os.asynctask.access$600(asynctask.java:177) 05-17 11:13:24.053: e/androidruntime(4284): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 05-17 11:13:24.053: e/androidruntime(4284): @ android.os.handler.dispatchmessage(handler.java:99) 05-17 11:13:24.053: e/androidruntime(4284): @ android.os.looper.loop(looper.java:137) 05-17 11:13:24.053: e/androidruntime(4284): @ android.app.activitythread.main(activitythread.java:5103) 05-17 11:13:24.053: e/androidruntime(4284): @ java.lang.reflect.method.invokenative(native method) 05-17 11:13:24.053: e/androidruntime(4284): @ java.lang.reflect.method.invoke(method.java:525) 05-17 11:13:24.053: e/androidruntime(4284): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 05-17 11:13:24.053: e/androidruntime(4284): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 05-17 11:13:24.053: e/androidruntime(4284): @ dalvik.system.nativestart.main(native method)
i'm need resolve posible. looking help.
update
sorry everyone, made mistake here. tab using fragment inside sliding menu.
i fixed it, sorry
Comments
Post a Comment