Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

android - java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin

I am currently working on an Android application with Kotlin in version 1.1.1

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 at com.package.fragment.ReminderAddFragment.onRetrieveBusinessObjects(ReminderAddFragment.kt:275) at com.smartnsoft.droid4me.app.Droid4mizer.onRetrieveBusinessObjects(Droid4mizer.java:552) at com.smartnsoft.droid4me.app.Droid4mizer.onRetrieveBusinessObjectsInternal(Droid4mizer.java:606) at com.smartnsoft.droid4me.app.Droid4mizer.access$000(Droid4mizer.java:46) at com.smartnsoft.droid4me.app.Droid4mizer$1.run(Droid4mizer.java:197) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

Here the code

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 ->
          //...
        }

        //...
      }
    }
  }
}

Where :

  • tutorialCategories is a List ;
  • tutorials is a List ;
  • reminders is a List ;

The line 275 of the code is mapOfreminders.forEach { _, finalReminders ->.

In the debugger, I can evaluate the mapOfreminders variable and everything seems to be alright.

If someone can help to resolve this issue !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

You could try to use another forEach with the single entry parameter that comes from the Kotlin standard library:

mapOfreminders.forEach { (_, finalReminders) -> }

Here the parentheses are used to destructure entry parameter into two variables: ignored key and finalReminders value.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...