类型不匹配:推断类型是GoogleSignInAccount? 但GoogleSignInAcc

2019-10-28 23:10发布

我想在登录谷歌添加到我的科特林但我在“USER_ACCOUNT”得到错误。 它说:“类型不匹配:推断类型是GoogleSignInAccount但GoogleSignInAccount预期?”如何纠正这个错误?

 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == RC_SIGN_IN) {
            val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
            try {
                val user_account = task.getResult(ApiException::class.java)
                firebaseAuthWithGoogle(user_account)
            } catch (e: ApiException) {
                Toast.makeText(this, "Google sign in failed:(", Toast.LENGTH_LONG).show()
            }
        }
    }

Answer 1:

GoogleSignIn.getSignedInAccountFromIntent是一个Java方法,因此它可以返回可空对象,但指定的非null类型。 所以,你要么指定类型Task<GoogleSignInAccount?>或使用可能的方式对象转换非空类型之一。

你可以阅读更多有关在这里 。



文章来源: Type mismatch: inferred type is GoogleSignInAccount? but GoogleSignInAccount was expected > Task :app:buildInfoGeneratorFdroidDebug