Reputation:
I'm trying to fetch data from my Firebase Database. I've initialized a variable called as tData
, which has some inputs from my Activity. In which I'm going to fetch data, tData
has been publically defined.
tData[10] =getArguments().getString("sLst");
I used a toast
to check if the contents are empty or not, and they aren't, tData[10]
has data, but still during the below operation
DatabaseReference databaseReference4 = firebaseDatabase.getReference("USERS/"+tData[10]+"/sList"); **
databaseReference4.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
tData[6]=dataSnapshot.getValue().toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
I get an error saying
NullPointerException,com.google.firebase.database.FirebaseDatabase.getReference(java.lang.String) on a null object reference at **
any inputs would be helpful
Upvotes: 0
Views: 239
Reputation: 839
Did you initialize firebaseDatabase object?
firebaseDatabase = FirebaseDatabase.getInstance();
Make sure you add this.
Upvotes: 1