我正在使用 Scala Liftweb 并拥有这个模型对象:
object Product extends Product with LongKeyedMetaMapper[Product] {
override def dbTableName = "products"
override def dbIndexes = UniqueIndex(slug) :: super.dbIndexes
def menus = sitemap
lazy val sitemap: List[Menu] = List(editProductMenuLoc, listProductsMenuLoc, createProductMenuLoc, indexProductsMenuLoc).flatten(a => a)
protected def editProductMenuLoc =
Full(Menu(Loc("EditProduct" + menuNameSuffix, editPath, S.?("edit.product"))))
protected def listProductsMenuLoc = Full(Menu(Loc("ListProduct" + menuNameSuffix, listPath, S.?("list.products"))))
protected def indexProductsMenuLoc = Full(Menu(Loc("ListProduct" + menuNameSuffix, indexPath, S.?("index.products"))))
protected def createProductMenuLoc =
Full(Menu(Loc("CreateProduct" + menuNameSuffix, createPath, S.?("create.product"))))
protected val menuNameSuffix = ""
protected val editSuffix = "edit"
protected val createSuffix = "create"
protected val viewSuffix = "view"
protected val editPath = theAdminPath(editSuffix)
protected val createPath = theAdminPath(createSuffix)
protected val viewPath = thePath(viewSuffix)
protected val listPath = basePath
protected val indexPath = adminPath
protected def thePath(end: String): List[String] = basePath ::: List(end)
protected def theAdminPath(end: String): List[String] = adminPath ::: List(end)
protected val basePath: List[String] = "products" :: Nil
protected val adminPath: List[String] = "admin" :: "products" :: Nil
}
当我编译时,它工作正常,一旦我尝试运行它,我得到这个错误:
Caused by: java.lang.NullPointerException: null
at scala.collection.immutable.List.$colon$colon$colon(List.scala:120) ~[scala-library.jar:0.12.2]
at code.model.Product$.theAdminPath(Product.scala:65) ~[classes/:na]
at code.Product$.<init>(Product.scala:53) ~[classes/:na]
at code.Product$.<clinit>(Product.scala) ~[classes/:na]
... 49 common frames omitted
我在MegaProtoMetaUser
源代码中找到的代码之后对这些路径进行了建模,但我不知道为什么这里会出现空指针异常 - 所有值都已正确填充,不是吗?