Consider:
mDatabase = FirebaseDatabase.getInstance().getReference("archive");
mDatabase.orderByChild("_age").equalTo("20").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
value = dataSnapshot.getValue(String.class);
tSResult.setText(value);
}
@Override
public void onCancelled(DatabaseError error) {
Log.w(TAG, "Failed to read value.", error.toException());
}
});
tSResult
is a TextView I'm using just to test the returned data.
I'm trying to run this code, but my application either crashes or does not return any result.
Log:
04-26 19:51:24.146 4372-4372/com.example.joe.orside E/AndroidRuntime:
FATAL EXCEPTION: main
Process: com.example.joe.orside, PID: 4372
com.google.firebase.database.DatabaseException: Failed to convert
value of type java.util.HashMap to String
at com.google.android.gms.internal.zzbqi.zzaD(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at
com.example.joe.orside.MainActivity$8$1.onDataChange(MainActivity.java:755)
at com.google.firebase.database.Query$1.onDataChange(Unknown Source)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Any suggestions?