Sahaj Rana Sahaj Rana - 1 year ago 1455
Android Question

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

I am using firebase to retrieve data from database n use

Map<String, String> map = dataSnapshot.getValue(Map.class);

to get values, but it shows error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rana.sahaj.myyu, PID: 13179 Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead
at Source)
at Source)
at Source)
at com.rana.sahaj.myyu.profile.Profile$2.onDataChange(
at Source)
at Source)
at$ Source)
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(
at dalvik.system.NativeStart.main(Native Method)

here's the code

DatabaseReference profileRef=mFirebaseRef.child(EEmail);
profileRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {

--> Map<String, String> map = (Map<String,String>)dataSnapshot.getValue(Map.class);

name = (TextView)findViewById(;
EmailView= (TextView)findViewById(;

PhotoUrl = map.get("picurl");

UserNam = map.get("userNAME");



public void onCancelled(DatabaseError firebaseError) {


n there is no problem with key n values in database.
used the solution but not working

Answer Source

The error points out correctly where you are going wrong

 Map<String, String> 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<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download