I'm trying to store the value of ds.getKey() to the global variable Common.workerType so that whenever I need to get a value from the database, I wouldn't have to repeat these set of codes over and over again, more ideally just to make it like this
final DatabaseReference dbRefChild = dbRef.child(Common.user_workers_table).child(Common.workerType).child(Common.uid);
I know that the error is showing because it's getting a null
data, but how come? I believe I got the right path of the nodes. This is the error I'm getting:
java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
final DatabaseReference newRef = FirebaseDatabase.getInstance().getReference();
final DatabaseReference newRefChild = newRef.child(Common.user_workers_table);
newRefChild.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()) {
if(ds.child(Common.uid).exists()) {
Common.workerType = ds.getKey();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Here's how the database looks like:
Common.user_workers_table refers to Workers
Common.workerType refers to Plumbers