android - can't BindViewHolder recyclerview when add header on scroll loard more -


i have tried add header in adapter can't bindviewholder. can me fixing these problems? here adapter code:

public class adapteritem extends recyclerview.adapter<recyclerview.viewholder>  {     private final int view_header=0;     private final int view_item = 1;     private final int view_prog = 2;      private arraylist<item> itemlist;      private onloadmorelistener onloadmorelistener;     private linearlayoutmanager mlinearlayoutmanager;      private boolean ismoreloading = false;     private int visiblethreshold = 1;     int firstvisibleitem, visibleitemcount, totalitemcount;      public interface onloadmorelistener{         void onloadmore();     }      public adapteritem(onloadmorelistener onloadmorelistener) {         this.onloadmorelistener=onloadmorelistener;         itemlist =new arraylist<>();     }      public void setlinearlayoutmanager(linearlayoutmanager linearlayoutmanager){         this.mlinearlayoutmanager=linearlayoutmanager;     }      public void setrecyclerview(recyclerview mview){         mview.addonscrolllistener(new recyclerview.onscrolllistener() {             @override             public void onscrolled(recyclerview recyclerview, int dx, int dy) {                 super.onscrolled(recyclerview, dx, dy);                 visibleitemcount = recyclerview.getchildcount();                 totalitemcount = mlinearlayoutmanager.getitemcount();                 firstvisibleitem = mlinearlayoutmanager.findfirstvisibleitemposition();                 if (!ismoreloading && (totalitemcount - visibleitemcount)<= (firstvisibleitem + visiblethreshold)) {                     if (onloadmorelistener != null) {                         onloadmorelistener.onloadmore();                     }                     ismoreloading = true;                 }             }         });     }      @override     public int getitemviewtype(int position) {         if(itemlist.get(position) != null && ispositionheader(position)){             return view_header;         }else if(itemlist.get(position) != null) {             return view_item;         }else{             return view_prog;         }     }     private boolean ispositionheader (int position) {         return position == 0;     }      @override     public recyclerview.viewholder oncreateviewholder(viewgroup parent,int viewtype) {         if (viewtype == view_header) {             return new studentviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.header, parent, false));         }else         if (viewtype == view_item) {             return new studentviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.item_text, parent, false));         }else {             return new progressviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.item_progress, parent, false));         }      }      public void addall(list<item> lst){         itemlist.clear();         itemlist.addall(lst);         notifydatasetchanged();     }      public void additemmore(list<item> lst){         itemlist.addall(lst);         notifyitemrangechanged(0,itemlist.size());     }      @override     public void onbindviewholder(recyclerview.viewholder holder, int position) {         if (holder instanceof studentviewholder) {             item singleitem = (item) itemlist.get(position);             ((studentviewholder) holder).tvitem.settext(singleitem.getitem());         }     }      public void setmoreloading(boolean ismoreloading) {         this.ismoreloading=ismoreloading;     }      @override     public int getitemcount() {         return itemlist.size();     }      public void setprogressmore(final boolean isprogress) {         if (isprogress) {             new handler().post(new runnable() {                 @override                 public void run() {                     itemlist.add(null);                     notifyiteminserted(itemlist.size() - 1);                     }                 });         } else {             itemlist.remove(itemlist.size() - 1);             notifyitemremoved(itemlist.size());         }     }      static class studentviewholder extends recyclerview.viewholder {         public textview tvitem;         public studentviewholder(view v) {             super(v);             tvitem = (textview) v.findviewbyid(r.id.tvitem);         }     }     static class progressviewholder extends recyclerview.viewholder {         public progressbar pbar;         public progressviewholder(view v) {             super(v);             pbar = (progressbar) v.findviewbyid(r.id.pbar);         }     } } 

here error log

11-10 14:02:12.115 2151-2151/com.esantiago.pagination e/androidruntime: fatal exception: main process: com.esantiago.pagination, pid: 2151 java.lang.nullpointerexception @ com.esantiago.pagination.adapter.adapteritem$override.onbindviewholder(adapteritem.java:105) @ com.esantiago.pagination.adapter.adapteritem$override.access$dispatch(adapteritem.java) @ com.esantiago.pagination.adapter.adapteritem.onbindviewholder(adapteritem.java:0) @ android.support.v7.widget.recyclerview$adapter.onbindviewholder(recyclerview.java:5465) @ android.support.v7.widget.recyclerview$adapter.bindviewholder(recyclerview.java:5498) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:4735) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:4611) @ android.support.v7.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:1988) @ android.support.v7.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1384) @ android.support.v7.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1347) @ android.support.v7.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:584) @ android.support.v7.widget.recyclerview.dispatchlayoutstep1(recyclerview.java:2977) @ android.support.v7.widget.recyclerview.dispatchlayout(recyclerview.java:2901) @ android.support.v7.widget.recyclerview.onlayout(recyclerview.java:3277) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.support.v4.widget.swiperefreshlayout.onlayout(swiperefreshlayout.java:596) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) @ android.widget.linearlayout.onlayout(linearlayout.java:1434) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.support.v7.widget.actionbaroverlaylayout.onlayout(actionbaroverlaylayout.java:435) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) @ android.widget.linearlayout.onlayout(linearlayout.java:1434) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14817) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:1983) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1740) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:996) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5600) @ 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:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ c


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -