android - RecyclerView error ConcurrentModificationException only API 23 & API 26 -
i concurrentmodificationexception in recyclerview, in apis 23 & 26, how can bypass this? recyclerview setup:
private void setuprecyclerview() { int maxindex = 0; if (game.size() < 3) { maxindex = game.size(); } else if (game.size() >= 3) { maxindex = 3; } recyclerview = findviewbyid(r.id.home_recycler_view); adapter = new gamecardlistminiadapter(this, game.sublist(0, maxindex)); recyclerview.setadapter(adapter); linearlayoutmanager linearlayoutmanager = new linearlayoutmanager(activityhome.this); linearlayoutmanager.setorientation(linearlayoutmanager.horizontal); recyclerview.sethasfixedsize(true); recyclerview.setlayoutmanager(linearlayoutmanager); recyclerview.setitemanimator(new defaultitemanimator()); }
after manipulate data game
, call recyclerview.swapadapter(adapter, true);
, error, in afore mentioned apis, in rest of apis api 15 works fine. stacktrace api 23:
e/surface: getslotfrombufferlocked: unknown buffer: 0xa0d2a5a0 d/androidruntime: shutting down vm e/androidruntime: fatal exception: main process: com.example.racu.cardgame, pid: 26900 java.util.concurrentmodificationexception @ java.util.abstractlist$subabstractlist.size(abstractlist.java:360) @ com.example.racu.cardgame.adapters.cardgamelistminiadapter.getitemcount(cardgamelistminiadapter.java:68) @ android.support.v7.widget.recyclerview.dispatchlayoutstep1(recyclerview.java:3603) @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:3103) @ android.view.view.measure(view.java:18788) @ android.support.v4.widget.nestedscrollview.measurechildwithmargins(nestedscrollview.java:1446) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.support.v4.widget.nestedscrollview.onmeasure(nestedscrollview.java:512) @ android.view.view.measure(view.java:18788) @ android.support.constraint.constraintlayout.internalmeasurechildren(constraintlayout.java:934) @ android.support.constraint.constraintlayout.onmeasure(constraintlayout.java:973) @ android.view.view.measure(view.java:18788) @ android.support.constraint.constraintlayout.internalmeasurechildren(constraintlayout.java:934) @ android.support.constraint.constraintlayout.onmeasure(constraintlayout.java:973) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18788) @ android.support.v4.widget.drawerlayout.onmeasure(drawerlayout.java:1060) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.support.v7.widget.contentframelayout.onmeasure(contentframelayout.java:139) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ com.android.internal.policy.phonewindow$decorview.onmeasure(phonewindow.java:2643) @ android.view.view.measure(view.java:18788) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2100) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1216) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1452) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1107) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6013) @ android.view.choreographer$callbackrecord.run(choreographer.java:858) @ android.view.choreographer.docallbacks(choreographer.java:670) @ android.view.choreographer.doframe(choreographer.java:606) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:844) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygot
this api 26:
d/egl_emulation: eglmakecurrent: 0x9d2e70a0: ver 2 0 (tinfo 0xa8e8b510) d/androidruntime: shutting down vm e/androidruntime: fatal exception: main process: com.example.racu.cardgame, pid: 4691 java.util.concurrentmodificationexception @ java.util.arraylist$sublist.size(arraylist.java:1057) @ com.example.racu.cardgame.adapters.cardgamelistminiadapter.getitemcount(cardgamelistminiadapter.java:68) @ android.support.v7.widget.recyclerview.dispatchlayoutstep1(recyclerview.java:3603) @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:3103) @ android.view.view.measure(view.java:21998) @ android.support.v4.widget.nestedscrollview.measurechildwithmargins(nestedscrollview.java:1446) @ android.widget.framelayout.onmeasure(framelayout.java:185) @ android.support.v4.widget.nestedscrollview.onmeasure(nestedscrollview.java:512) @ android.view.view.measure(view.java:21998) @ android.support.constraint.constraintlayout.internalmeasurechildren(constraintlayout.java:934) @ android.support.constraint.constraintlayout.onmeasure(constraintlayout.java:973) @ android.view.view.measure(view.java:21998) @ android.support.constraint.constraintlayout.internalmeasurechildren(constraintlayout.java:934) @ android.support.constraint.constraintlayout.onmeasure(constraintlayout.java:973) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1514) @ android.widget.linearlayout.measurevertical(linearlayout.java:806) @ android.widget.linearlayout.onmeasure(linearlayout.java:685) @ android.view.view.measure(view.java:21998) @ android.support.v4.widget.drawerlayout.onmeasure(drawerlayout.java:1060) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.framelayout.onmeasure(framelayout.java:185) @ android.support.v7.widget.contentframelayout.onmeasure(contentframelayout.java:139) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1514) @ android.widget.linearlayout.measurevertical(linearlayout.java:806) @ android.widget.linearlayout.onmeasure(linearlayout.java:685) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.framelayout.onmeasure(framelayout.java:185) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1514) @ android.widget.linearlayout.measurevertical(linearlayout.java:806) @ android.widget.linearlayout.onmeasure(linearlayout.java:685) @ android.view.view.measure(view.java:21998) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:6580) @ android.widget.framelayout.onmeasure(framelayout.java:185) @ com.android.internal.policy.decorview.onmeasure(decorview.java:721) @ android.view.view.measure(view.java:21998) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2410) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1498) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1751) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1386) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6733) @ android.view.choreographer$callbackrecord.run(choreographer.java:911) @ android.view.choreographer.docallbacks(choreographer.java:723) @ android.view.choreographer.doframe(choreographer.java:658) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:897) @ android.os.handler.handlecallback(handler.java:789) @ android.os.handler.dispatchmessage(handler.java:98) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) 08-14 18:50:44.793 4691-4691/com.example.racu.cardgame e/androidruntime: @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)
tried make work creating game.sublist outside,with for
loop instead of sublist
, didn't crash, swapadapter
wasn't being called , strange thing is working wonderful in phone, no crashes , expected behavior.
i really,really apreciate light. regards ne0r@cu
try
recyclerview.layoutmanager layoutmanager = new linearlayoutmanager(this);
instead of :
linearlayoutmanager linearlayoutmanager = new linearlayoutmanager(activityhome.this);
then same thing ext
rc.sethasfixedsize(false);//only use fixed ammount rc.setlayoutmanager(layoutmanager); rc.setadapter(dataitemadapter);
Comments
Post a Comment