0

これは私を夢中にさせています-私はscala、ソーシャルセキュアなどでプレイに取り組んでおり、ケースクラスを作成しようとするとこのエラーが発生し続けます.

編集: これと同様の質問: Scala and Play2: ClassCastException: java.lang.Object cannot be cast to play.api.libs.json.JsValue

編集: メソッド createIdentityFromUser を静的コンパニオン クラスに移動すると、これが修正されるようです。理由がわからない。

[ClassCastException: java.lang.Object cannot be cast to securesocial.core.SocialUser] 
In /Users/tripled153/Development/src/Foundation/playApp/app/service/SecureSocialUserService.scala     at line 58.
54//    }
55
56    println("here2")
57    //val ret = user.map(_.createIdentityFromUser)
58    user.foreach(x => x.createIdentityFromUser)
59    user match{
60      case Some(x) => Some(x.createIdentityFromUser)
61      case None => None

Line42 エラーが発生しました。マップ、foreach、およびその classcastexception を使用したすべての爆弾に一致しますが、その理由がわかりません。

読みやすくするためにコードを少しクリーンアップしたものを次に示します (SocialUser extends Identity traits に注意してください)。

  def find(id: UserId): Option[Identity] = {
   if ( Logger.isDebugEnabled ) {
     Logger.debug("find users = %s".format(users))
   }

   //Option[GraphedUser]
   val user = GraphedUser.getUser(id.id)

   //ret should be Option[SocialUser]
   val ret = user.map(_.createIdentityFromUser) //errors!

   return ret

 }

そして、問題と思われるオブジェクトを生成するために呼び出されるメソッド。これは、tinkerpop フレームの VertexFrame インターフェイスを拡張するトレイトにあります。それと何か関係があると思います。

  def createIdentityFromUser: SocialUser = {

    return new SocialUser(new UserId(getUserId, getProviderId), getFirstName, getLastName, getName, Some(getEmail),
      None, new AuthenticationMethod("userPassword"), None, None, Some(new PasswordInfo(getPasswordInfoHash, getPasswordInfoSalt)))

  }
4

1 に答える 1

0

メソッドを静的にしてパラメーターを取得すると機能します...理由はわかりませんが、問題は解決しました。Javaでは、これは発生しません。

于 2013-02-05T00:24:24.337 に答える