java - Exception occurring in PagerAdapter -
this exception occurring , little of phone.
the exception:
java.lang.illegalstateexception: application's pageradapter changed adapter's contents without calling pageradapter#notifydatasetchanged! expected adapter item count: 0, found: 5 pager id: com.cutv.mobile.zshdclient:id/vp_content_newslist pager class: class android.support.v4.view.viewpager problematic adapter: class com.cutv.mobile.zs.hdclient.activity.newslistactivity$categoryadapter @ android.support.v4.view.viewpager.populate(viewpager.java:967) @ android.support.v4.view.viewpager.populate(viewpager.java:919) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1441) @ android.view.view.measure(view.java:16508) @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:719) @ android.widget.relativelayout.onmeasure(relativelayout.java:455) @ android.view.view.measure(view.java:16508) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:16508) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1404) @ android.widget.linearlayout.measurevertical(linearlayout.java:695) @ android.widget.linearlayout.onmeasure(linearlayout.java:588) @ android.view.view.measure(view.java:16508) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2291) @ android.view.view.measure(view.java:16508) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1994) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1191) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1373) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1078) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5687) @ android.view.choreographer$callbackrecord.run(choreographer.java:761) @ android.view.choreographer.docallbacks(choreographer.java:574) @ android.view.choreographer.doframe(choreographer.java:544) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5014) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:805) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:621) @ dalvik.system.nativestart.main(native method)
the code:
public class newslistactivity extends baseactivity implements view.onclicklistener { private intent msuperintent; private pageindicator mindicator; private viewpager mviewpager; private list<newsfragment> mlist; private categoryadapter madapter; private int mtitle; private progressbar mwait_pb; private categoryloadtask cdt; private string tag = "news"; @override protected int setlayout() { return r.layout.activity_newslist; } @override protected void initbase() { mwait_pb = (progressbar) findviewbyid(r.id.pb_wait_newslist); mindicator = (pageindicator) findviewbyid(r.id.indicator_newslist); mviewpager = (viewpager) findviewbyid(r.id.vp_content_newslist); mlist = new arraylist<newsfragment>(); logutils.printdebug(tag, mlist.size() + "first"); cdt = new categoryloadtask(); cdt.execute(); logutils.printdebug(tag, mlist.size() + "four"); } @override public void onclick(view v) { int id = v.getid(); if (id == r.id.btn_back_title) { finishcurrentactivity(); cdt.cancel(true); mlist.clear(); mlist=null; mviewpager.clearfocus(); mviewpager=null; mindicator =null; } } private class categoryadapter extends fragmentpageradapter { public categoryadapter(fragmentmanager fm) { super(fm); } @override public int getcount() { logutils.printdebug(tag, mlist.size() + "five"); return mlist.size(); } @override public charsequence getpagetitle(int position) { return mlist.get(position).getinfo().title; } @override public fragment getitem(int arg0) { return mlist.get(arg0); } } private class categoryloadtask extends asynctask<object, void, void> { private string scontent; @override protected void onpreexecute() { super.onpreexecute(); mwait_pb.setvisibility(view.visible); madapter = new categoryadapter(getsupportfragmentmanager()); mviewpager.setadapter(madapter); mindicator.setviewpager(mviewpager); } @override protected void doinbackground(object... params) { string categorytype = "news"; if (mtitle == r.string.life) { categorytype = "life"; } else if (mtitle == r.string.goverment_affairs) { categorytype = "gov"; } scontent = wapi.get_content_from_remote_url( wapi.wapi_get_category_url + categorytype, 10000); return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); wapi.parse_category_content(scontent, mlist); logutils.printdebug(tag, mlist.size() + "third"); madapter.notifydatasetchanged(); mindicator.notifydatasetchanged(); mwait_pb.setvisibility(view.gone); } } @override protected void ondestroy() { // todo auto-generated method stub super.ondestroy(); cdt.cancel(true); mlist.clear(); mlist=null; mviewpager.clearfocus(); mviewpager=null; mindicator =null; } }
Comments
Post a Comment