我一直在寻找可以广泛帮助我的代码的答案,但是我发现的解决方案对我不起作用.
我收到以下错误:
kotlin.TypeCastException: null cannot be cast to non-null type kotlin.collections.Map<kotlin.String, kotlin.Any> FATAL EXCEPTION: main Process: com.meetHitch.HitchApp, PID: 4021 kotlin.TypeCastException: null cannot be cast to non-null type kotlin.collections.Map<kotlin.String, kotlin.Any> at ... helpers.RestAPIKt$getUserProfile ... at com.Google.androID.gms.tasks.zzj.run(UnkNown Source) at androID.os.Handler.handleCallback(Handler.java:751) at androID.os.Handler.dispatchMessage(Handler.java:95) at androID.os.Looper.loop(Looper.java:154) at androID.app.ActivityThread.main ... at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$Method... at com.androID.internal.os.ZygoteInit.main
我的代码如下:
private val TAG: Stringget() = "RestAPI"private val fUser: FirebaseUser?get() = FirebaseAuth.getInstance().currentUserprivate val uID: String?get() = fUser?.uIDprivate val baseDoc: documentReferenceget() = FirebaseFirestore.getInstance(). collection("users").document(uID!!)private val leadsDoc: documentReferenceget() { appUser.currentConference?.ID?.let { return baseDoc.collection("leads").document(it) } return baseDoc.collection("leads").document(demoID)}private val conferencesCollection: CollectionReferenceget() = FirebaseFirestore.getInstance(). collection("conferences")fun getUserProfile(callback: (AppUser) -> Unit) { // Source can be CACHE, SERVER, or DEFAulT. val source = Source.DEFAulT baseDoc.get(source) .addOnCompleteListener { task -> if (task.isSuccessful) { val document = task.result if (document != null) { printnLog(TAG, "Loaded profile for User with UID: $uID successfully!") val user = AppUser(task.result.data as Map<String, Any>) callback(user) } else { println("No profile set. Saving initial profile...") appUser = AppUser(fUser!!) setUserProfile() } } else { Log.w(TAG, "getUser:onCancelled", task.exception) } } }
我指的是kotlin.TypeCastException: null cannot be cast to non-null type com.midsizemango.databasekotlin.Note,尽管有可能我没有实现,但所有解决方案都没有起作用?在正确的地方.我尝试了“ as?Map”,但出现类型不匹配错误.
解决方法:
使用val user = AppUser(task.result.data as Map< String,Any>)行,使Any变量可为空:
val user = AppUser(task.result.data as Map<String, Any?>)
总结 以上是内存溢出为你收集整理的android-kotlin.TypeCastException:无法将null强制转换为非null类型的kotlin.collections.Map全部内容,希望文章能够帮你解决android-kotlin.TypeCastException:无法将null强制转换为非null类型的kotlin.collections.Map所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)