Skip to content Skip to sidebar Skip to footer

Getting Data From Firebase Using Orderbychild Query

I have a String stationName and I want to fetch distance from FireBase according to the stationName I provided. Here is my Firebase Database: I am using orderByChild query to filt

Solution 1:

Replace this

for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
            distance = dataSnapshot.child("Distance").getValue(String.class);
            tt.setText(distance); //to check if it is working or not
        }

With this

for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
            distance = snapshot.child("Distance").getValue().toString(); // you //cannot pass the String.class as in the getValue() parameters becasue a long value //can not be cast to class object so you need to call toString() method to convert long value //into the string value.
            tt.setText(distance); //to check if it is working or not
        }

Hope it helps

Post a Comment for "Getting Data From Firebase Using Orderbychild Query"