android - arraylist is empty after adding values -


when execute program, shows blank screen , in logcat shows no adapter attached; skipping layout. when debug code arraylist not getting value (returning 0).

public class mainactivity extends appcompatactivity implements constants, networkoperation, url {      linearlayoutmanager manager;     arraylist<offermodal> bestoffers;     recyclerviewadapter adapter;     recyclerview rv;     fetchdata fetchdata;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         rv = (recyclerview) findviewbyid(r.id.recyclerview1);          fetchdata = new fetchdata(this, this, cloud_section);         fetchdata.fromserver();         manager = new linearlayoutmanager(getapplicationcontext(), linearlayoutmanager.vertical, false);         rv.setlayoutmanager(new linearlayoutmanager(this));      }      @override     public void started() {      }      @override     public void doingbackground() {      }      @override     public void completed(jsonobject jsonobject) {          bestoffers = new arraylist<offermodal>();          try {              jsonarray array_item = new jsonarray();             (int = 0; < array_item.length(); i++) {                  jsonobject itemobj = array_item.getjsonobject(i);                 string id = itemobj.getstring(id);                 string le_id = itemobj.getstring(le_id);                 string title = itemobj.getstring(title);                 string description = itemobj.getstring(description);                 string wid = itemobj.getstring(wid);                 string hgt = itemobj.getstring(hgt);                 string tn_path = itemobj.getstring(tn_path);                 string create_time = itemobj.getstring(create_time);                 string update_time = itemobj.getstring(update_time);                 string view_count = itemobj.getstring(view_count);                 string slide_count = itemobj.getstring(slide_count);                 string shared = itemobj.getstring(shared);                 string publish_ver = itemobj.getstring(publish_ver);                 string publish_time = itemobj.getstring(publish_time);                 string user_name = itemobj.getstring(user_name);                 string avatar_path = itemobj.getstring(avatar_path);                 string comment_count = itemobj.getstring(comment_count);                 string fav = itemobj.getstring(fav);                 string fav_count = itemobj.getstring(fav_count);                  offermodal off = new offermodal(id, le_id, title, description, wid, hgt, tn_path, create_time, update_time, view_count, slide_count, shared, publish_ver, publish_time, user_name, avatar_path, comment_count, fav, fav_count);                  off.setid(id);                 off.setid(le_id);                 off.settitle(title);                 off.setdescription(description);                 off.sethgt(hgt);                 off.settn_path(tn_path);                 off.setcreate_time(create_time);                 off.setupdate_time(update_time);                 off.setview_count(view_count);                 off.setslide_count(slide_count);                 off.setshared(shared);                 off.setpublish_ver(publish_ver);                 off.setpublish_time(publish_time);                 off.setuser_name(user_name);                 off.setavatar_path(avatar_path);                 off.setcomment_count(comment_count);                 off.setfav(fav);                 off.setfav_count(fav_count);                 bestoffers.add(off);              }          } catch (jsonexception e) {             e.printstacktrace();         }          adapter = new recyclerviewadapter(getapplicationcontext(), bestoffers);         rv.setadapter(adapter);      }  } 

this json data:

[   {     "id": "42057",     "le_id": "568fb0d29a5eb",     "title": "bag big deal lulu hypermarket",     "description": "",     "wid": "0",     "hgt": "0",     "tn_path": "",     "create_time": "1452257490",     "update_time": "1452332748",     "view_count": "00000000669",     "slide_count": "9",     "shared": "f",     "publish_ver": "11",     "publish_time": "1452332761",     "user_name": " lulu retail",     "avatar_path": null,     "comment_count": "0",     "fav": "f",     "fav_count": 0   },   {     "id": "42019",     "le_id": "568f9e45625da",     "title": "bag big deal lulu fashion store",     "description": "",     "wid": "0",     "hgt": "0",     "tn_path": "",     "create_time": "1452252741",     "update_time": "1452584969",     "view_count": "00000000659",     "slide_count": "1",     "shared": "f",     "publish_ver": "5",     "publish_time": "1452584972",     "user_name": " lulu retail",     "avatar_path": null,     "comment_count": "0",     "fav": "f",     "fav_count": 0   },   {     "id": "42017",     "le_id": "568f9e30df0da",     "title": "bag big deal lulu connect",     "description": "",     "wid": "0",     "hgt": "0",     "tn_path": "",     "create_time": "1452252720",     "update_time": "1452585162",     "view_count": "00000000726",     "slide_count": "7",     "shared": "f",     "publish_ver": "7",     "publish_time": "1452275301",     "user_name": " lulu retail",     "avatar_path": null,     "comment_count": "0",     "fav": "f",     "fav_count": 0   } ] 

this adapter class:

public class recyclerviewadapter extends recyclerview.adapter<recyclerviewholder> {      arraylist<offermodal> mbestoffers;     context context;     //  list<offers>card_items;      requestqueue mrequestqueue;     imageloader mimageloader;      public recyclerviewadapter(context context, arraylist<offermodal> mbestoffers) {         this.context = context;         // this.card_items = card_items;         this.mbestoffers = mbestoffers;          mrequestqueue = volley.newrequestqueue(context);         mimageloader = new imageloader(mrequestqueue, new imageloader.imagecache() {             private final lrucache<string, bitmap> mcache = new lrucache<string, bitmap>(10);              public void putbitmap(string url, bitmap bitmap) {                 mcache.put(url, bitmap);             }              public bitmap getbitmap(string url) {                 return mcache.get(url);             }         });      }      @override     public recyclerviewholder oncreateviewholder(viewgroup parent, int viewtype) {         view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.cardlayout, null);         recyclerviewholder rvh = new recyclerviewholder(view);          return rvh;     }      @override     public void onbindviewholder(recyclerviewholder holder, int position) {        //      holder.imageview.setimageurl(mbestoffers.get(position).getavatar_path(), mimageloader);        holder.tv1.settext(mbestoffers.get(position).gettitle());        //write code download image , data server , set here      }      @override     public int getitemcount() {         return mbestoffers.size();     } } 

please me solve issue, greately appriciated.

please paste jsonobject.tostring() in completed().

array empty reason here.

       jsonarray array_item = new jsonarray();         (int = 0; < array_item.length(); i++) { 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -