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

后端 未结 6 1256
既然无缘
既然无缘 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:48

    The error points out correctly where you are going wrong

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

    Map class uses parameter to define the types of Key and Object where as you don't give them and simply use Map.class which fails.

    Try the below code - since Key are always string and we can have any type of Object for them

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

提交回复
热议问题