I can not find solution to the "java.lang.NullPointerException" Error - Android Studio

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 displaying 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 can not seem to figure it out. Thanks for the help.

    
asked by anonymous 12.11.2017 / 15:00

1 answer

1

You used the equals method when dataSnapshot.child("ImagemPerfilURL").getValue() is null.

If child "ImagemPerfilURL" can not be null, then this is the real problem, with NullPointerException being just the result.

    
12.11.2017 / 20:39