Skip to content
Advertisement

In my chat app i have this error java.lang.NullPointerException

I making chat app .. and I have this problem when i click in any user to start chat with him. but for first time when i get into chat and i send first message it has been sent “in my firebase i see it”but when i am trying to get chat again this error occur ..

JavaScript

So, this is my code ..

JavaScript

and this is my Model ..

JavaScript

so this error occur when i get into my users fragment and click into any user to start chat with him .. any one can help me with that ?

Advertisement

Answer

in your code chat.getReceiver() & chat.getSender() are returning null values and you have many calls like chat.getReceiver().equals(myUid) & chat.getSender().equals(hisUid) and all of them can product NullPointerException.

So correct getReceiver() and getSender() codes and make sure they do not return null values or check for null before calling equals on them.

Or change chat.getSender().equals(hisUid) to hisUid.equals(chat.getSender()) and chat.getReceiver().equals(myUid) to myUid.equals(chat.getReceiver()) if hisUid and myUid always are not null.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement