1

I'm having issues getting data snapshots value and i believe its because I'm wanting to access a Hashmap<String,Hashmap>() value. Is there a way for me to obtain all the data snapshot and put it into a class in my app?

Here's the sample error output:

 W/System.err: com.google.firebase.database.DatabaseException:
 Class java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead

Sample Code:

RootRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                try {
                    if(dataSnapshot.exists()){
                        GenericTypeIndicator<Users> u = new GenericTypeIndicator<Users>(){};
                        Users usersData = dataSnapshot.getValue(u);
            }
       }
   }
}

Here's a screenshot of the realtime database.

Firebase Realtime Database

This is my Users Class:

public class Users {
    private String id, name, phone, email,points, upline;
    private HashMap<String, String> downlines, orderHistory;
    private HashMap<String, HashMap> transactions;

    public Users(){

    }

    public Users(String id, String name, String phone, String email, String points, HashMap orderHistory, String upline, HashMap downlines, HashMap transactions) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.email = email;
        this.points =points;
        this.orderHistory = orderHistory;
        this.downlines = downlines;
        this.upline = upline;
        this.transactions = transactions;
    }

The error indicates that I have issues on Users usersData = dataSnapshot.getValue(u);

  • How is `RootRef` defined? And what is the expected result? – Alex Mamo Aug 05 '19 at 07:00
  • 1
    Possible duplicate of [Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead](https://stackoverflow.com/questions/37688031/class-java-util-map-has-generic-type-parameters-please-use-generictypeindicator) – Ashish Aug 05 '19 at 13:25
  • @AlexMamo RootRef was declared as `FirebaseDatabase.getInstance().getReference().child(parentDbName).child(uid);`. I'm expecting there would not be any errors and all the data is stored within the Users class – Philip Teng Aug 06 '19 at 08:01
  • Show us also the content of your `Users` class. And also what is the expected result? – Alex Mamo Aug 06 '19 at 08:03
  • https://stackoverflow.com/q/46276806/7254873 – Sumit Shukla Aug 06 '19 at 08:31

1 Answers1

0

I've changed the private Hashmap<String, Hashmap> transactions in Users class into Hashmap<String, Object> transactions and it works out perfectly.