【问题标题】:authentication and firestore error - NullPointerException [duplicate]身份验证和 Firestore 错误 - NullPointerException [重复]
【发布时间】:2019-11-03 14:33:26
【问题描述】:

当我添加 Firestore 云依赖项时,我的应用会在用户注销时崩溃

   kotlin.KotlinNullPointerException
            at com.example.proghelp.ProfileActivity$read_write_fire$2.onEvent(ProfileActivity.kt:93)
            at com.example.proghelp.ProfileActivity$read_write_fire$2.onEvent(ProfileActivity.kt:35)
            at com.google.firebase.firestore.DocumentReference.zza(Unknown Source)
            at com.google.firebase.firestore.zzd.onEvent(Unknown Source)
            at com.google.android.gms.internal.firebase-firestore.zzkp.zza(Unknown Source)
            at com.google.android.gms.internal.firebase-firestore.zzkq.run(Unknown Source)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4517)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
            at dalvik.system.NativeStart.main(Native Method)

我的 firebase 依赖项

 implementation 'com.google.firebase:firebase-core:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.google.firebase:firebase-database:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    implementation 'com.google.android.gms:play-services-auth:15.0.0'
    implementation 'com.firebaseui:firebase-ui-database:3.1.3'
    implementation 'com.firebaseui:firebase-ui-storage:3.2.1'
    implementation 'com.google.firebase:firebase-analytics:15.0.0'
    implementation 'com.google.firebase:firebase-firestore:15.0.0'
    implementation 'com.android.support:multidex:1.0.3'

我的日志在 tis 代码中:

 var db = FirebaseFirestore.getInstance();
       val notebookRef3 = db.collection(currentuser.uid)

 notebookRef3.document("name").addSnapshotListener { querySnapshot, e ->
            var note = querySnapshot!!.toObject(Note2::class.java)
           var name = note!!.username
            iduserprofile.text = name
        }

它说日志在这里

   var note = querySnapshot!!.toObject(Note2::class.java)

【问题讨论】:

    标签: android kotlin nullpointerexception google-cloud-firestore firebase-authentication


    【解决方案1】:

    querySnapshot 可以为 null,但您使用 !! 运算符强制取消引用它,而无需先检查它。不要那样做——总是检查空值。如果querySnapshot 为空,则意味着异常e 将不为空,您应该记录该异常。

    这可能是权限错误导致侦听器由于安全规则而失败,因为用户不再使用有效凭据登录。

    【讨论】:

    • 请您帮忙编写正确的代码
    猜你喜欢
    • 2019-08-13
    • 2016-06-07
    • 2021-10-17
    • 1970-01-01
    • 2018-09-26
    • 2013-11-03
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    相关资源
    最近更新 更多