Ad
Get Hashmap Values From Realtime Database
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.
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);
Ad
Answer
I've changed the private Hashmap<String, Hashmap> transactions
in Users class into Hashmap<String, Object> transactions
and it works out perfectly.
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad