我正在制作一個聊天應用程式,當我登錄時,我在Logcat中收到此錯誤并且我的應用程式崩潰。
2022-03-12 16:09:44.805 22115-22115/com.dccodes.chugli E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dccodes.chugli, PID: 22115
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.dccodes.chugli.MainActivity$2.onDataChange(MainActivity.java:91)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
我不明白為什么會出現此錯誤,我在我的應用程式中使用了 firebase。我的主要活動非常大,所以我上傳了代碼照片。

我不明白為什么我會收到這個錯誤。
uj5u.com熱心網友回復:
嘗試使用“addListenerForSingleValueEvent(new ValueEventListener() {”而不是“ValueEventListener”因為每次你在'reference'樹中發生變化時都會觸發ValueEvetListener,如果沒有任何反應,它不會被觸發,這段代碼也不會跑步。
但是 addListenerForSingleValueEvent 無論如何都會運行這個代碼塊一次。
還要檢查“參考”是否指向您想要收聽的火力基地中的確切位置。如果正確,請檢查它指向的用戶是否為空。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/442307.html
標籤:安卓 火力基地 firebase-实时数据库 日志猫
上一篇:添加Firestore規則“&&request.auth.uid==userId;”導致“快照偵聽器中的錯誤:FirebaseError:缺少權限或權限不足。”
