Meher Meher - 1 year ago 141
Android Question

Android Firebase query data

Im trying to query data from firebase database.Below images show data structure. enter image description here.Im trying to query messages by data(long value is the time in milli seconds).Below is the code :

database.child("Market").child("data").child("messages").orderByKey().startAt("1473777076600").addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {

MessageFirebaseHelper data = dataSnapshot.getValue(MessageFirebaseHelper.class);

Object[] messageKeys = data.getMessages().keySet().toArray();

for(int i=0;i<messageKeys.length;i++){
Logger.i(TAG, " messages keys : " + messageKeys[i]);


public void onCancelled(DatabaseError databaseError) {


Below is the error:

W/ClassMapper(8838): No setter/field for 1473777892283 found on class

As the keys change dynamically, creating getter/setter is not correct.
How do i get the data and save it ?

TRY 2:

I tried in different way, Query :

.startAt("1473777076600").addListenerForSingleValueEvent(new ValueEventListener() {

This does not return any value.

Answer Source

Try like this,,

public void onDataChange(DataSnapshot dataSnapshot) {

     for (DataSnapshot eventSnapshot : dataSnapshot.getChildren()) {

            yourModel mModel = eventSnapshot.getValue(yourModel.class);
            Log.e("DATA" ,""+ mModel);   

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download