问题描述
我目前正在使用 Kotlin 1.1.1 版开发 Android 应用程序
I am currently working on an Android application with Kotlin in version 1.1.1
在我的代码中,为了读取多个 MutableList
和 MutableMap
,我使用了多个 forEach
结构.
In my code, I have imbrication of several forEach
structures in order to read several MutableList
and MutableMap
.
不幸的是,我的应用程序崩溃并显示以下堆栈跟踪:
Unfortunately, my app crashes with the following stacktrace :
java.lang.NoClassDefFoundError:com.package.fragment.ReminderAddFragment$onRetrieveBusinessObjects$$inlined$forEach$lambda$1在com.package.fragment.ReminderAddFragment.onRetrieveBusinessObjects(ReminderAddFragment.kt:275)在com.smartnsoft.droid4me.app.Droid4mizer.onRetrieveBusinessObjects(Droid4mizer.java:552)在com.smartnsoft.droid4me.app.Droid4mizer.onRetrieveBusinessObjectsInternal(Droid4mizer.java:606)在com.smartnsoft.droid4me.app.Droid4mizer.access$000(Droid4mizer.java:46)在 com.smartnsoft.droid4me.app.Droid4mizer$1.run(Droid4mizer.java:197)在java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)在 java.util.concurrent.FutureTask.run(FutureTask.java:237) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)在 java.lang.Thread.run(Thread.java:818)
这里是代码
tutorialCategories.forEach { (_, _, _, _, _, tutorials) ->
tutorials.forEach { tutorial ->
if (tutorial.id == simpleReminderFromExtra.tutorialId)
{
//...
val mapOfreminders = mutableMapOf<Int, MutableList<Reminder>>()
val reminders = ReminderServices.getReminderByTutorialId(simpleReminderFromExtra.tutorialId)
reminders.forEach { reminder ->
//...
}
mapOfreminders.forEach { _, finalReminders ->
//...
finalReminders.forEach { reminder ->
//...
}
//...
}
}
}
}
哪里:
tutorialCategories
是一个List
;tutorials
是一个List
;reminders
是一个List
;
tutorialCategories
is aList
;tutorials
is aList
;reminders
is aList
;
代码的第 275 行是 mapOfreminders.forEach { _, finalReminders ->
.
The line 275 of the code is mapOfreminders.forEach { _, finalReminders ->
.
在调试器中,我可以评估 mapOfreminders
变量,一切似乎都没有问题.
In the debugger, I can evaluate the mapOfreminders
variable and everything seems to be alright.
如果有人可以帮助解决这个问题!
If someone can help to resolve this issue !
推荐答案
阅读 Dan Lew 的 post 几天前,我会建议使用 Map.forEach { k, v ->}
来自 Java 8 的方法,该方法可能在 Android 运行时中不可用.
After reading Dan Lew's post a couple days ago, I'll make a suggestion that this can be caused by using Map.forEach { k, v -> }
method from Java 8, which may be unavailable in Android runtime.
您可以尝试使用另一个 forEach 带有来自 Kotlin 标准库的单入口参数:
You could try to use another forEach with the single entry parameter that comes from the Kotlin standard library:
mapOfreminders.forEach { (_, finalReminders) -> }
这里的括号用于将入口参数分解为两个变量:忽略的键和finalReminders
值.
Here the parentheses are used to destructure entry parameter into two variables: ignored key and finalReminders
value.
这篇关于Kotlin 中的 java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!