-4
2020-03-23 13:16:34.533 26427-26427/com.android.text E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.text, PID: 26427
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
        at com.android.text.MainActivity$1.onDataChange(MainActivity.java:54)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.1:75)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.1:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.1:55)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:6518)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50

1 Answers1

0

Check the line 54 of your main activity. The string which it is trying to interact with is null so you cannot invoke methods or properties on it.

Without see your actual code I would suggest a protective change to check fo null first as follows

String thisCouldBeNull = "Some value that could be null";
if ((thisCouldBeNull != null) && (thisCouldBeNull.equals("what you are checking")) {
// Do Something Positive
}
Captain Wizard
  • 331
  • 2
  • 9
  • line 15 if(user.getImageURL().equals("default")){ – Sadeeq Rabiu Mar 23 '20 at 12:38
  • i override a method onDataChange (@NonNull DataShot – Sadeeq Rabiu Mar 23 '20 at 12:41
  • while this answers the question, there is no use in explaining how to get rid of a NPE since this is covered in the mentioned question. – f1sh Mar 23 '20 at 12:44
  • You gotta start somewhere so happy to help... You could change your code to... String userImage = user.getImageUrl(); if (userImage == null) { //Error handle as something could be wrong } else if (userImage.equals("defualt") { //Do what you need to do } Strings in Java can be null, therefore unless you know the object will always give you a valid string (eg empty or a value) then you should protect for null isntances – Captain Wizard Mar 23 '20 at 14:36