如何为scala.collection.mutable.Hashmap指定SerialVersionUID?

时间:2015-05-07 19:06:08

标签: scala serialization

我有一个使用java.io序列化的保存游戏。保存为Hashmap[String, Any]Any中包含的类都具有Seri​​alVersionUID(1L)。我使用sbt配置https://github.com/ajhager/libgdx-sbt-project.g8

当我使用desktop/run启动项目时,它工作正常,但assembly生成的jar会抛出此错误:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.io.InvalidClassException: scala.collection.mutable.HashMap; local class incompatible: stream classdesc serialVersionUID = 1, local class serialVersionUID = -1796852918056492754
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.io.InvalidClassException: scala.collection.mutable.HashMap; local class incompatible: stream classdesc serialVersionUID = 1, local class serialVersionUID = -1796852918056492754
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    at ntn.castersrun.IntoFileSaver$.getSave(IntoFileSaver.scala:34)
    at ntn.castersrun.IntoFileSaver$.load(IntoFileSaver.scala:24)

我可能应该保存为元组数组,但我无法弄清楚是什么原因造成了这个错误或者我怎么能解决它。

0 个答案:

没有答案