Skip to content

按照官方的都加了kotlinx.serialization,但还是一直报 java.io.NotSerializableException #41

@code-rebooter

Description

@code-rebooter

下面是我的代码:

plugins { id 'org.jetbrains.kotlin.multiplatform' version '2.0.0' id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0' }

id 'kotlinx-serialization'

implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1"

var userList :MutableList<UserInfo> by serialLazy(arrayListOf())

`import kotlinx.serialization.Serializable

@serializable
data class UserInfo (
var name: String? = null,
var age: Int? = null
)`

` val a = UserInfo()
a.age = 17
a.name = "zegyue"

    val b = UserInfo()
    b.age = 18
    b.name = "zegyu1e"
    val alist = mutableListOf(a,b)
    AppCache.userList = alist`

报错: java.lang.Error: java.io.NotSerializableException: com.chihi.m98.bean.UserInfo at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1173) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) Caused by: java.io.NotSerializableException: com.chihi.m98.bean.UserInfo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions