类型不匹配:推断的类型是GoogleSignInAccount?但是GoogleSignInAccount应该是>任务:app:buildInfoGeneratorFdroidDebug [英] Type mismatch: inferred type is GoogleSignInAccount? but GoogleSignInAccount was expected > Task :app:buildInfoGeneratorFdroidDebug
问题描述
我正在尝试将Google登录添加到我的Kotlin中,但是在"user_account"处出现错误.它说:类型不匹配:推断的类型是GoogleSignInAccount?但应使用GoogleSignInAccount" 如何纠正此错误?
I am trying to add google sign-in to my kotlin but I am getting error at "user_account". It says "Type mismatch: inferred type is GoogleSignInAccount? but GoogleSignInAccount was expected" How to rectify this error?
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()
}
}
}
推荐答案
这可能是一个较晚的答案,但希望它可以在将来对像我这样的Kotlin初学者有所帮助.
This maybe a late answer, but hopefully it can help the Kotlin beginners like me in the future.
我遇到了完全相同的错误,并进行了以下修改以解决该问题:
I met exactly the same error, and modify as the following part to fix it:
val user_account : GoogleSignInAccount? = task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(user_account!!)
您可以参阅Kotlin在线文档零安全,以了解有关以下内容的详细信息: null和"!!"运算符.
You may refer to Kotlin online document Null Safety for the details about null and "!!" operator.
这篇关于类型不匹配:推断的类型是GoogleSignInAccount?但是GoogleSignInAccount应该是>任务:app:buildInfoGeneratorFdroidDebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!