在下面的kotlin代码中,我得到了这个类型不匹配错误。我在这里只包含了相关的代码。
如何修复此错误?
如何将AnnotatedData<SomeType!>!
转换为SomeType
谢谢
Type mismatch: inferred type is AnnotatedData<LeaderboardsClient.LeaderboardScores!>! but LeaderboardsClient.LeaderboardScores was expected
...
import com.google.android.gms.games.LeaderboardsClient
import com.google.android.gms.games.leaderboard.LeaderboardScore
import com.google.android.gms.games.leaderboard.LeaderboardScoreBuffer
...
private fun getLeaderboardData(leaderboardID: String, result: Result) {
showLoginErrorIfNotLoggedIn(result)
leaderboardsClient!!
.loadTopScores(leaderboardID, 2, 0, 10)
.addOnSuccessListener { scores ->
val leaderboardScores: LeaderboardsClient.LeaderboardScores
leaderboardScores = scores
val out = "score"
result.success(out)
}.addOnFailureListener {
result.error("error", "Unknown error", null)
}
}
...
发布于 2021-03-17 15:50:01
我找到了一个解决方案。我不确定这是不是一个像样的,因为我是kotlin的新手。但至少它是有效的。
...
import com.google.android.gms.games.AnnotatedData
...
private fun getLeaderboardData(leaderboardID: String, result: Result) {
showLoginErrorIfNotLoggedIn(result)
leaderboardsClient!!
.loadTopScores(leaderboardID, 2, 0, 10)
.addOnSuccessListener { scores ->
val leaderboardScores: LeaderboardsClient.LeaderboardScores?
val annotatedData: AnnotatedData<LeaderboardsClient.LeaderboardScores>
annotatedData = scores
leaderboardScores = annotatedData.get()
...
}.addOnFailureListener {
result.error("error", "Unknown error", null)
}
}
...
https://stackoverflow.com/questions/66674578
复制相似问题