1
The following error appears:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at novapetbeta.platypus.com.novapetbeta.Principal$6.onChildAdded(Principal.java:185)
at com.google.android.gms.internal.zzdri.zza(Unknown Source:33)
at com.google.android.gms.internal.zzdwu.zzbvb(Unknown Source:2)
at com.google.android.gms.internal.zzdxa.run(Unknown Source:65)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
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)
This is the code that is showing the error.
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.exists() && !dataSnapshot.child("connections").child("Meh").hasChild(atualUID) && !dataSnapshot.child("connections").child("Gostei").hasChild(atualUID)){
String ImagemPerfilURL = "default";
if (!dataSnapshot.child("ImagemPerfilURL").getValue().equals("default")){
ImagemPerfilURL = dataSnapshot.child("ImagemPerfilURL").getValue().toString();
}
I’m new to mobile development and I’m not getting around to it. Thanks for your help.
Observing the error message we see that
Attempt to invoke virtual method '...equals...' on a null object reference
=> "Tried to executeequals
about something that isnull
". It certainly refers to this linedataSnapshot.child("ImagemPerfilURL").getValue().equals("default")
in whichdataSnapshot.child("ImagemPerfilURL").getValue()
must be bringingnull
. Start there, trying to understand what this part gives as value and why. Can and should always do Debug the application and use the Logcat to try to extract as much information as possible and understand what values are in each part of the code– Isac
NullPointerException
it is becausedataSnapshot.child("ImagemPerfilURL").getValue()
isnull
or no empty, you are making an equals of an empty variable, check the JSON path, it can be this– Costamilam