Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead

后端 未结 6 1258
既然无缘
既然无缘 2020-11-29 09:11

I am using firebase to retrieve data from database n use

Map map = dataSnapshot.getValue(Map.class);

to get values, but it

6条回答
  •  星月不相逢
    2020-11-29 09:39

    You need to use the getCheldrin as follows

    for (DataSnapshot snapshotNode: dataSnapshot.getChildren()) {
        map.put(snapshotNode.getKey(), snapshotNode.getValue(YOUR_CLASS_TYPE.class));
    }
    

    Replace the YOUR_CLASS_TYPE with the class type you expecting. notice that this class must have an empty constructor.

提交回复
热议问题