所以我试图更好地组织我的包,在将一些类移动到另一个包之后,我的代码现在给了我这个异常:
Exception in thread "main" scala.reflect.internal.MissingRequirementError: class Track not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
at scala.reflect.internal.Mirrors$RootsBase.ensureClassSymbol(Mirrors.scala:90)
at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:119)
at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:21)
at scala.pickling.internal.package$.typeFromString(package.scala:61)
at scala.pickling.internal.package$$anonfun$2.apply(package.scala:63)
at scala.pickling.internal.package$$anonfun$2.apply(package.scala:63)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at scala.pickling.internal.package$.typeFromString(package.scala:63)
at scala.pickling.FastTypeTag$.apply(FastTags.scala:57)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:204)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:193)
at scala.pickling.PickleTools$class.withHints(Tools.scala:425)
at scala.pickling.json.JSONPickleReader.withHints(JSONPickleFormat.scala:159)
at scala.pickling.json.JSONPickleReader.beginEntry(JSONPickleFormat.scala:193)
at scala.pickling.json.JSONPickleReader.beginEntryNoTag(JSONPickleFormat.scala:192)
at BillboardsHot100.deserializeTrackList(Billboards.scala:60)
at BillboardsHot100.checkForChanges(Billboards.scala:31)
at Main$.main(Main.scala:7)
at Main.main(Main.scala)
如果我将所有内容都放在同一个包中或在同一个文件中声明这些类,它就可以正常工作。
有人可以告诉我如何解决这个问题吗?
已解决:如果也有这个问题,问题在于 Pickling 如何序列化。在 json 中,有一个字段 'tpe' 用于类型,它从
"tpe": "Track"
至
"tpe": "com.new.package.path.Track"
这是新包(不是我的包名)。希望这个例子可以在未来帮助其他人。