I have a problem several days ago and I don't find a solution.
I´m trying search in my firebase database by name but the result is always null.
The database is the next;

The code that I use is the next;
final String nombre = edtNombreJugador.getText().toString().trim().toUpperCase();
mDatabase.child("user").child("personalData").orderByChild("name").equalTo(nombre);
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
String title = (String) singleSnapshot.child("name").getValue(String.class);
System.out.println("TITLE: "+title);
}
Title always return null in my case.
Can somebody help me please? I don't know what I'm doing bad...
Right now you're querying the database path /user/personalData. And then for each child node under there, you're comparing the name property to the value the user entered. So /user/personalData/***/name.
That doesn't match the path in the database, which is /user/***/personalData/name. To query that you do:
Query query = mDatabase.child("user").orderByChild("personalData/name").equalTo(nombre);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With