Why am I getting java.util.ConcurrentModificationException on Android Gridview? -


i have task load images website , load them gridview. when try update mangagridarrayadapter error:

08-24 21:03:03.433  22791-22791/com.solomobile.englishmanga w/system.err﹕ java.util.concurrentmodificationexception 08-24 21:03:03.433  22791-22791/com.solomobile.englishmanga w/system.err﹕ @ java.util.abstractlist$subabstractlist.size(abstractlist.java:360) 08-24 21:03:03.434  22791-22791/com.solomobile.englishmanga w/system.err﹕ @ java.util.abstractlist$subabstractlist.addall(abstractlist.java:280) 08-24 21:03:03.434  22791-22791/com.solomobile.englishmanga w/system.err﹕ @ android.widget.arrayadapter.addall(arrayadapter.java:195) 08-24 21:03:03.434  22791-22791/com.solomobile.englishmanga w/system.err﹕ @ com.solomobile.englishmanga.task.popularmangatask.onpostexecute(popularmangatask.java:128) 08-24 21:03:03.434  22791-22791/com.solomobile.englishmanga w/system.err﹕ @ com.solomobile.englishmanga.task.popularmangatask.onpostexecute(popularmangatask.java:19) 

following code task:

package com.solomobile.englishmanga.task;

import android.app.activity; import android.content.context; import android.os.asynctask; import android.widget.gridview; import android.widget.abslistview; import com.solomobile.englishmanga.r; import com.solomobile.englishmanga.adapter.mangagridarrayadapter; import com.solomobile.englishmanga.controller.englishmangacontroller; import com.solomobile.englishmanga.domain.manga; import com.solomobile.englishmanga.util.util;  import java.util.list;  public class popularmangatask extends asynctask<context, void, void> {      private activity activity = null;     private mangagridarrayadapter mangagridarrayadapter = null;     private list<manga> mangas = null;     string erro = null;     private final int max_per_page = 6;     private int currentpage = 0;     private static boolean loading = new boolean(false);        public activity getactivity() {         return activity;     }      public void setactivity(activity activity) {         this.activity = activity;     }      @override     protected synchronized void doinbackground(context... params) {         this.activity = (activity) params[0];         if(mangas == null) {             system.out.println("getting mangas first time");             englishmangacontroller controller = englishmangacontroller.getinstance();             mangas = controller.getpopularmangas();             list<manga> mangalist = mangas.sublist(currentpage * max_per_page, (currentpage * max_per_page) + max_per_page);             englishmangacontroller.getinstance().definemangacover(mangalist);             mangagridarrayadapter = new mangagridarrayadapter(activity, mangalist);         }else{             system.out.println("loading more covers");             list<manga> mangalist = mangas.sublist(currentpage * max_per_page, (currentpage * max_per_page) + max_per_page);             englishmangacontroller.getinstance().definemangacover(mangalist);         }         system.out.println("previous current page: " + currentpage);         currentpage++;         system.out.println("after current page: " + currentpage);         return null;     }      public int getcurrentpage() {         return currentpage;     }      public void setcurrentpage(int currentpage) {         this.currentpage = currentpage;     }      public list<manga> getmangas() {         return mangas;     }      public void setmangas(list<manga> mangas) {         this.mangas = mangas;     }      public mangagridarrayadapter getmangagridarrayadapter() {         return mangagridarrayadapter;     }      public void setmangagridarrayadapter(mangagridarrayadapter mangagridarrayadapter) {         this.mangagridarrayadapter = mangagridarrayadapter;     }      @override     protected synchronized void onpostexecute(void result) {         super.onpostexecute(result);         try{             gridview gridview = (gridview) activity.findviewbyid(r.id.gridviewpopular);             if(gridview != null){                 if(currentpage == 1) {                     gridview.setadapter(mangagridarrayadapter);                     gridview.setonscrolllistener(new abslistview.onscrolllistener() {                         @override                         public void onscrollstatechanged(abslistview view, int scrollstate) {                          }                          @override                         public synchronized void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {                             int lastinscreen = firstvisibleitem + visibleitemcount;                             int maxpages = (int)(mangas.size() / max_per_page);                             system.out.println("scrolling - currentpage: " + currentpage + " max pages: " + maxpages + " loading: " + loading);                             if (!loading && lastinscreen == totalitemcount && currentpage <= maxpages) {                                 loading = true;                                 system.out.println("call new popular manga task: " + loading);                                     popularmangatask popularmangatask = new popularmangatask();                                     popularmangatask.setcurrentpage(currentpage);                                     popularmangatask.setmangas(mangas);                                     popularmangatask.setmangagridarrayadapter(mangagridarrayadapter);                                     util.startmytask(popularmangatask, activity);                             }                         }                     });                 }else{                     system.out.println("adding more mangas popular list - current page: " + currentpage);                     int maxsublist = (currentpage * max_per_page) + max_per_page;                     if(maxsublist >= mangas.size()){                         maxsublist = mangas.size()-1;                     }                     system.out.println("maxsublist: " + maxsublist);                     system.out.println("mangas.size: " + mangas.size()); //                    mangagridarrayadapter = new mangagridarrayadapter(activity, mangas.sublist(0, maxsublist)); //                    mangagridarrayadapter.clear(); //                    mangagridarrayadapter.getmangas().clear(); //                    list<manga> sublistmanga = mangas.sublist(currentpage * max_per_page,maxsublist);                     list<manga> sublistmanga = mangas.sublist(8,maxsublist > mangas.size() ? mangas.size() : maxsublist);                     system.out.println("sublistmanga.size: " + sublistmanga.size());                     mangagridarrayadapter.addall(sublistmanga); //                    loading = false;                 }             }         }catch (exception e){             e.printstacktrace();         }      } } 

and here code adapter:

package com.solomobile.englishmanga.adapter;  import java.util.list;  import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.textview;  import com.solomobile.englishmanga.r; import com.solomobile.englishmanga.controller.englishmangacontroller; import com.solomobile.englishmanga.domain.manga; import com.squareup.picasso.picasso;  public class mangagridarrayadapter extends arrayadapter<manga>{     private final context context;     private final list<manga> mangas;      public list<manga> getmangas() {         return mangas;     }      public mangagridarrayadapter(context context, list<manga> mangas) {         super(context, r.layout.manga_grid_layout, mangas);         this.context = context;         this.mangas = mangas;     }      @override     public view getview(final int position, view convertview, viewgroup parent) {         layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);         final view rowview = inflater.inflate(r.layout.manga_grid_layout, parent, false);         final manga selectedmanga = mangas.get(position);         final imageview imageview = (imageview) rowview.findviewbyid(r.id.iconmanga);         system.out.println("loading image: " + selectedmanga.getcoverlink());          picasso.with(context).load(selectedmanga.getcoverlink()).into(imageview);          textview textview = (textview) rowview.findviewbyid(r.id.name);         textview.settext(selectedmanga.getname());         return rowview;     } } 

what doing wrong in case? have quite same code working listview, gridview i'm getting this.

how can without getting error?

add method mangagridarrayadapter

public void addallmanga(list<manga> list) {     for(int = 0; < list.size(); i++) {         mangas.add(list.get(i));     }     notifydatasetchanged(); } 

in task

mangagridarrayadapter.addallmanga(sublistmanga); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -