【问题标题】:NotSerializableException on class, but there's no Item class in my project?NotSerializableException 类,但我的项目中没有 Item 类?
【发布时间】:2020-02-28 20:15:02
【问题描述】:

我有一个名为 Items 的类,它是用 Serializable 实现的,但是当读取数据时,系统提示我在 Item 上出现 NotSerializableException 错误(如下图链接) 在我的项目中不存在而不是 Items 类。我试图重建和清理项目,但它仍然是一样的。感谢您的帮助,因为我完全不知道......

public class Items implements Serializable {
   private String item;
   private String date;

   public Items(String item, String date) {
      this.item = item;
      this.date = date;
   }

   public String getItem() {
      return item;
   }

   public void setItem(String item) {
      this.item = item;
   }

   public String getDate() {
      return date;
   }

   public void setDate(String date) {
      this.date = date;
   }
}

如下图:

Error on NotSerializableException image

【问题讨论】:

    标签: serializable notserializableexception


    【解决方案1】:

    我无权发表评论,因此以写作作为答案。

    请尝试使用 Items 对象重新生成文件,然后尝试反序列化它。 可能文件是旧的,它是使用 Item 类而不是 Items 创建的。

    【讨论】:

    • 我只是尝试删除 Items 类文件并再次重新生成 Items 类文件而不进行序列化,但是当我调试我的代码时,它仍然指向我的 Item 类不是序列化而不是新的 Items 类.......
    • 叹息。我指的是重新创建您正在反序列化的数据文件。我认为该文件是使用 Item 类创建的。
    • 天哪,我在我的模拟器中卸载了该应用程序并重新安装,现在它可以工作了..无论如何谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 2022-11-11
    • 1970-01-01
    相关资源
    最近更新 更多