简体   繁体   English

尝试在 android studio firebase mainactivity 中的空对象引用上调用虚方法 boolean java.lang.String.equals(java.lang.Object)

[英]Attempt to invoke virtual method boolean java.lang.String.equals(java.lang.Object) on a null object reference in android studio firebase mainactivity

I am making a chatting application in which when I login, I get this error in Logcat and my app crashes.我正在制作一个聊天应用程序,当我登录时,我在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)

I don't understand why I get this error, I used firebase for my app.我不明白为什么会出现此错误,我在我的应用程序中使用了 firebase。 My main activity is very large, so I uploaded the photo of code.我的主要活动很大,所以我上传了代码的照片。

在此处输入图像描述 在此处输入图像描述

I don't understand why I get this error.我不明白为什么会出现此错误。

Try using addListenerForSingleValueEvent(new ValueEventListener() { instead of ValueEventListener Because ValueEventListener is triggered everytime that you have a change in 'reference' tree, if nothing happens it won't be triggered, and this block of code won't run.尝试使用addListenerForSingleValueEvent(new ValueEventListener() {而不是ValueEventListener因为每次更改“引用”树时都会触发ValueEventListener ,如果没有任何反应,它不会被触发,并且此代码块将不会运行。

However addListenerForSingleValueEvent runs this block of code one time no matter what.然而, addListenerForSingleValueEvent无论如何都会运行这段代码一次。

Also check that 'refernece' is pointing to the exact place in your Firebase that you want to listen to.还要检查“refernece”是否指向您想要收听的 Firebase 中的确切位置。 And if it's right check that the user it's pointing to isn't null.如果正确,请检查它指向的用户是否不为空。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android firebase crashlytics 无法在 null ZA8CFDE6331BD59EB2AC966F8911Z4B6 上调用方法 all() - android firebase crashlytics Cannot invoke method all() on null object 在 java.lang.String 类型的对象的 JSON 反序列化期间出现问题 - Issue during JSON deserialization of an object of type java.lang.String java.lang.AbstractMethodError 在 Firebase Android (FirebaseInstallationServiceClient.readGenerateAuthTokenResponse) - java.lang.AbstractMethodError in Firebase Android (FirebaseInstallationServiceClient.readGenerateAuthTokenResponse) java.lang.IllegalArgumentException:给定的字符串为空或 null - java.lang.IllegalArgumentException: Given String is empty or null com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.projects.inputData - com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.projects.inputData Android studio null object 参考错误 - Android studio null object reference error DataBaseException:无法将 java.lang.String 类型的 object 转换为 com.example.testingeverything.ShippingDetail 类型,我尝试了一切来修复它 - DataBaseException: Can't convert object of type java.lang.String to type com.example.testingeverything.ShippingDetail, I tried everything to fix it Firebase DatabaseException:无法将 java.lang.Long 类型的值转换为字符串 - Firebase DatabaseException: Failed to convert value of type java.lang.Long to String java.lang.IllegalArgumentException:项目 ID 不能为 null 或为空 - java.lang.IllegalArgumentException: The project ID can't be null or empty com.google.firebase.database.DatabaseException:无法将 java.lang.Long 类型的值转换为字符串...显示特定行的错误 - com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String...shows error for a specific line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM