RuntimeException:异常充气Kotlin:Navigation/nav_graph

发布于 2025-02-05 07:42:28 字数 131 浏览 2 评论 0原文

当我们将SafeArgs放入导航图中时,我们有一个Runtime Exception,此崩溃并没有为我们提供任何修复指南。 在第一印象中,我们正在遵循此过程,以确保这些班级是否是包裹的。

因此,这些班级正确地被包裹了,一切似乎都正确。

We had a RuntimeException while we put a safeArgs into the navigation graph and this crash didn't give us any more guide to fix it.
In the first impression, we were following this to ensure that those classes were Parcelize or not.

Therefore, those classes were parceled correctly and everything seems right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信愁 2025-02-12 07:42:28

在对我们的代码进行了多次搜索和调查之后,我发现Safeargs类中存在于密封级文件中

考虑到这一点,我们不能将包裹的注释分配给密封的类,我们决定将班级移到该密封的.kt文件之外。

虽然,我发现该运行时崩溃的主要原因是此原因。

另外,我在下面提供了错误和正确的案例,我们希望这对他人有帮助:

我们已经将userfavorite及其子类移动到wheSPT.kt文件之外,

sealed class Response {
.
.
 
    @Parcelize
        data class UserFavorite(
            @SerializedName("title") val title: String,
            @SerializedName("itemType") val itemType: String,
            @SerializedName("emptyIcon") val emptyIcon: String,
            @SerializedName("_texts") val texts: UserFavoriteTexts
        ) : Response(), Parcelable
  

    @Parcelize
    data class UserFavoriteTexts(
        @SerializedName("hintMessage") val hintMessage: String,
        @SerializedName("add") val add: String,
        @SerializedName("remove") val remove: String,
        @SerializedName("edit") val edit: String
        ): Parcelable

.
.
}

将其移至一个独立的文件中:userfavorite.kt.kt

@Parcelize
    data class UserFavorite(
        @SerializedName("title") val title: String,
        @SerializedName("itemType") val itemType: String,
        @SerializedName("emptyIcon") val emptyIcon: String,
        @SerializedName("_texts") val texts: UserFavoriteTexts
    ) : Response(), Parcelable
  

@Parcelize
data class UserFavoriteTexts(
    @SerializedName("hintMessage") val hintMessage: String,
    @SerializedName("add") val add: String,
    @SerializedName("remove") val remove: String,
    @SerializedName("edit") val edit: String
    ): Parcelable

并且,响应

sealed class Response {
.
.
 
.
.
}

After many searches and investigations into our codes, I found that SafeArgs class exists in a sealed-class file.

Considering to this point that we can't allocate the parceled annotation to the sealed classes, we've decided to move our class outside of that sealed .kt file.

Although, I found the main reason for that runtime crash was this cause.

Also, I've provided the wrong and correct cases below, We hope this will be helpful to others:

We've moved the UserFavorite and its subclass, outside of the Response.kt file,

sealed class Response {
.
.
 
    @Parcelize
        data class UserFavorite(
            @SerializedName("title") val title: String,
            @SerializedName("itemType") val itemType: String,
            @SerializedName("emptyIcon") val emptyIcon: String,
            @SerializedName("_texts") val texts: UserFavoriteTexts
        ) : Response(), Parcelable
  

    @Parcelize
    data class UserFavoriteTexts(
        @SerializedName("hintMessage") val hintMessage: String,
        @SerializedName("add") val add: String,
        @SerializedName("remove") val remove: String,
        @SerializedName("edit") val edit: String
        ): Parcelable

.
.
}

into an independent file for that: UserFavorite.kt

@Parcelize
    data class UserFavorite(
        @SerializedName("title") val title: String,
        @SerializedName("itemType") val itemType: String,
        @SerializedName("emptyIcon") val emptyIcon: String,
        @SerializedName("_texts") val texts: UserFavoriteTexts
    ) : Response(), Parcelable
  

@Parcelize
data class UserFavoriteTexts(
    @SerializedName("hintMessage") val hintMessage: String,
    @SerializedName("add") val add: String,
    @SerializedName("remove") val remove: String,
    @SerializedName("edit") val edit: String
    ): Parcelable

and, Respons.kt

sealed class Response {
.
.
 
.
.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文