我试图在RecyclerView中选择和删除类别,但某些特定的手机品牌(Android版本8或9)出现UnsupportedOperationException。
我的代码:
holder.checkBox.setOnCheckedChangeListener { _, isChecked ->
if (isChecked){
mListener.onItemSelected(position,true) //CategoryAdapter.kt:42
mSelectedItems.add(position)
}else{
mListener.onItemSelected(position,false)
mSelectedItems.remove(position)
}
//notifyDataSetChanged()
}
//
//
private var categoriesDefault = mutableListOf<String>()
override fun onItemSelected(position: Int, isSelected: Boolean) {
if (isSelected){
categoriesDefault.add(categoriesValues[position]) //CategoryFragment.kt:19
}else{
categoriesDefault.remove(categoriesValues[position])
}
tinyDB.categories = categoriesDefault
}
致命错误日志:
#0. Crashed: main
at java.util.AbstractList.add + 148(AbstractList.java:148)
at java.util.AbstractList.add + 108(AbstractList.java:108)
at com.blarma.high5.aui.base.wordsetting.CategoryFragment.onItemSelected + 19(CategoryFragment.kt:19)
at com.blarma.high5.aui.base.wordsetting.CategoryAdapter$onBindViewHolder$1.onCheckedChanged + 42(CategoryAdapter.kt:42)
at android.widget.CompoundButton.setChecked + 182(CompoundButton.java:182)
at android.widget.CompoundButton.toggle + 136(CompoundButton.java:136)
at android.widget.CompoundButton.performClick + 141(CompoundButton.java:141)
at android.view.View.performClickInternal + 7305(View.java:7305)
at android.view.View.access$3200 + 846(View.java:846)
at android.view.View$PerformClick.run + 27787(View.java:27787)
at android.os.Handler.handleCallback + 873(Handler.java:873)
at android.os.Handler.dispatchMessage + 99(Handler.java:99)
at android.os.Looper.loop + 214(Looper.java:214)
at android.app.ActivityThread.main + 7078(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main + 964(ZygoteInit.java:964)
编辑:更多日志在这里 我不知道问题出在哪里,但希望有人能解决。而且由于“您的帖子似乎大部分是代码;请添加更多详细信息。”而无法发布更多信息。错误。
#1. Answers Events Handler1
at java.lang.Object.wait(Object.java)
at java.lang.Thread.parkFor$ + 2137(Thread.java:2137)
at sun.misc.Unsafe.park + 358(Unsafe.java:358)
at java.util.concurrent.locks.LockSupport.parkNanos + 230(LockSupport.java:230)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos + 2101(AbstractQueuedSynchronizer.java:2101)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take + 1132(ScheduledThreadPoolExecutor.java:1132)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take + 849(ScheduledThreadPoolExecutor.java:849)
at java.util.concurrent.ThreadPoolExecutor.getTask + 1092(ThreadPoolExecutor.java:1092)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1152(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun + 75(ExecutorUtils.java:75)
at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run + 30(BackgroundPriorityRunnable.java:30)
at java.lang.Thread.run + 764(Thread.java:764)
#2. Crashlytics Exception Handler1
at dalvik.system.VMStack.getThreadStackTrace(VMStack.java)
at java.lang.Thread.getStackTrace + 1538(Thread.java:1538)
at java.lang.Thread.getAllStackTraces + 1588(Thread.java:1588)
at com.crashlytics.android.core.CrashlyticsController.writeSessionEvent + 1340(CrashlyticsController.java:1340)
at com.crashlytics.android.core.CrashlyticsController.writeFatal + 1027(CrashlyticsController.java:1027)
at com.crashlytics.android.core.CrashlyticsController.access$500 + 69(CrashlyticsController.java:69)
at com.crashlytics.android.core.CrashlyticsController$7.call + 328(CrashlyticsController.java:328)
at com.crashlytics.android.core.CrashlyticsController$7.call + 321(CrashlyticsController.java:321)
at java.util.concurrent.FutureTask.run + 266(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun + 75(ExecutorUtils.java:75)
at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run + 30(BackgroundPriorityRunnable.java:30)
at java.lang.Thread.run + 764(Thread.java:764)