null for argument 'pathString'

Viewed 16151

I am having an error when I perform queries in firebase, my code for query looks like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_perfil);

txtNome = (TextView) findViewById(R.id.txtNomePerfil);
txtCpf = (TextView) findViewById(R.id.txtCpfPerfil);
txtEmail = (TextView) findViewById(R.id.txtEmailPerfil);
txtFone = (TextView) findViewById(R.id.txtCelularPerfil);
txtPlaca = (TextView) findViewById(R.id.txtPlacaPerfil);
imgPerfil = (ImageView) findViewById(R.id.imgPerfil);
txtNomeFantasia = (TextView) findViewById(R.id.txtNomeFantasiaPerfil);
txtCnpj = (TextView) findViewById(R.id.txtCnpjPerfil);

firebaseUser = firebaseAuth.getInstance().getCurrentUser();

uId = firebaseUser.getUid();
email = firebaseUser.getEmail();
txtEmail.setText(email);

databaseReference = FirebaseDatabase.getInstance().getReference();

databaseReference.child("Usuario").child(uId).child("nome")
        .addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
              nome = dataSnapshot.getValue(String.class);
                txtNome.setText(nome);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });


  DatabaseReference mReferenceCpf = FirebaseDatabase.getInstance().getReference();
databaseReference.child("Usuario").child(uId).child("cnpjCpf")
        .addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
             cpf = dataSnapshot.getValue(String.class);
                txtCpf.setText(cpf);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });



   DatabaseReference mReferencePlaca = FirebaseDatabase.getInstance().getReference();
    mReferencePlaca.child("Funcionario").child(cpf).child("placa")
            .addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    placa = dataSnapshot.getValue(String.class);
                    txtPlaca.setText(placa);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

However I am getting the following error:

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{ucarparceiro.ucarapp.com.ucarparceiro/ucarparceiro.ucarapp.com.ucarparceiro.Activity.ActivityPrincipal.ActivityPerfil}: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2316) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2376) android.app.ActivityThread.access$800 (ActivityThread.java:147) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1281) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:135) android.app.ActivityThread.main (ActivityThread.java:5253) java.lang.reflect.Method.invoke (Method.java) java.lang.reflect.Method.invoke (Method.java:372) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:899) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:694)

The data in Firebase is as follows:

User Employee

4 Answers
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

In the onCreate() method, initialize the FirebaseAuth instance and the AuthStateListener method so you can track whenever the user signs in or out.

mAuth = FirebaseAuth.getInstance();


mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    FirebaseUser user = firebaseAuth.getCurrentUser();
    if (user != null) {
        // User is signed in
        Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
    } else {
        // User is signed out
        Log.d(TAG, "onAuthStateChanged:signed_out");
    }
    // ...
}

};

Attach the listener to your FirebaseAuth instance in the onStart() method and remove it on onStop().

  public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);

}

public void onStop() {
super.onStop();
if (mAuthListener != null) {
    mAuth.removeAuthStateListener(mAuthListener);
}

}

https://firebase.google.com/docs/auth/android/start/?hl=es-419

not sure if this solution will be helpful for others.

background : I was setting firebase path value with intent parcel.

Solution : resolved this issue by updating androidmenifest as adding 'singleInstance'

    <activity android:name=".yourActivity"
              android:launchMode="singleInstance"
              android:parentActivityName=".MainActivity">
Related