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

generictypeindicator kotlin
hashmap has generic type parameters
com google firebase database databaseexception class java util map has generic type parameters
error on parameter params java java util map java lang string java lang object
map map datasnapshot getvalue map class
datasnapshot to hashmap

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
                                                                 com.google.firebase.database.DatabaseException: Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead
                                                                     at com.google.android.gms.internal.zzaix.zzb(Unknown Source)
                                                                     at com.google.android.gms.internal.zzaix.zza(Unknown Source)
                                                                     at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
                                                                     at com.rana.sahaj.myyu.profile.Profile$2.onDataChange(Profile.java:158)
                                                                     at com.google.android.gms.internal.zzafp.zza(Unknown Source)
                                                                     at com.google.android.gms.internal.zzagp.zzSu(Unknown Source)
                                                                     at com.google.android.gms.internal.zzags$1.run(Unknown Source)
                                                                     at android.os.Handler.handleCallback(Handler.java:733)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     at android.os.Looper.loop(Looper.java:136)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5052)
                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                                     at dalvik.system.NativeStart.main(Native Method)

here's the code

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

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

            name = (TextView)findViewById(R.id.UserInActivity);
            EmailView= (TextView)findViewById(R.id.emailUser);

            PhotoUrl = map.get("picurl");
             emmaill=map.get("userEmail");

            UserNam = map.get("userNAME");

            name.setText(UserNam);
            EmailView.setText(emmaill);


        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {

        }
    });

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

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();

Android, From looking at your DB, it looks like you should use int or long type instead of the map type, since your timestamp has a number value. Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead 2 Not a direct subclass of GenericTypeIndicator: class com.google.firebase.database.GenericTypeIndicator

To introduce the GenericTypeIndicator, you can change this line:

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

in to this:

GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {};
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator );

This should work well in your case. Please give it a try and let me know.

Class java.util.List has generic type parameters, please use , But then I get the error. Class java.util.List has generic type parameters, please use GenericTypeIndicator instead exception. JSON structure of my database: When you try to retrieve a object and turn it to a object with a generic with type parameters EX (a Map/HashMap) you get the error Could not deserialize object. Class java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead

I had the same problem and solved it by handling the Object instead trying to have Firebase cast it.

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

did it for me.

GenericTypeIndicator missing from firestore library but required , GitHub is home to over 50 million developers working together to host and Class java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead onEvent(Unknown Source:6) at com.google. firebase.firestore.util. public static <T> Map<String, T> toMapWithValues(Class <T>� Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead (3) 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

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.

GenericTypeIndicator, PID: 13179 com.google.firebase.database.DatabaseException: Class java.util. Map has generic type parameters, please use GenericTypeIndicator instead at� Overview; auth:import and auth:export; Firebase Realtime Database Operation Types; Deploy Targets; Cloud Firestore Index Definition Format

Due to the way that Java implements generics (type-erasure), it is necessary to use a slightly more complicated method to properly resolve types for generic collections at runtime. To solve this problem, Firebase Database accepts subclasses of this class in calls to getValue (getValue(GenericTypeIndicator), getValue(GenericTypeIndicator)) and returns a properly-typed generic collection.

As an example, you might do something like this to get a list of Message instances from a DataSnapshot:

 class Message {
     private String author;
     private String text;

     private Message() {}

     public Message(String author, String text) {
         this.author = author;
         this.text = text;
     }

     public String getAuthor() {
         return author;
     }

     public String getText() {
         return text;
     }
 }

 // Later ...

 GenericTypeIndicator<List<Message>> t = new GenericTypeIndicator<List<Message>>() {};
 List<Message> messages = snapshot.getValue(t);

Class java.util.ArrayList has generic type parameters, use , public abstract class GenericTypeIndicator extends Object. Due to the way that Java implements generics (type-erasure), it is necessary to use� 50 Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead 42 Designing labels/text views with custom fonts in Interface Builder 33 How to handle notification when app in background in Firebase

com.google.firebase.database.DatabaseException: Class java.util , DatabaseException: Class java.util.ArrayList has generic type parameters, please use GenericTypeIndicator instead Класс java.util.Map имеет общие параметры типа, вместо этого используйте GenericTypeIndicator Я использую firebase для извлечения данных из базы данных n use

关于Android:Android-类java.util.Map具有通用类型参数,请改用 , java.util.List has generic type parameters, please use GenericTypeIndicator instead. This crash was crawled from Stack Overflow 2 years ago� /** * Converts a standard library Java representation of JSON data to an object of the class provided * through the GenericTypeIndicator * * @param object The representation of the JSON data * @param typeIndicator The indicator providing class of the object to convert to * @return The POJO object.

Larry McKenzie, Android - Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead我知道有很多类似的问题,例如我的,但我� */ public static <T> T convertToCustomClass(Object object, Class<T> clazz) { return deserializeToClass(object, clazz); } /** * Converts a standard library Java representation of JSON data to an object of the class provided * through the GenericTypeIndicator * * @param object The representation of the JSON data * @param typeIndicator The

Comments
  • can you update your question with the new code you used ?
  • use getValue() you are still doing getValue(Map.class);
  • See my correct answer down below. as no solution here worked for me
  • getting this error now java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
  • Map<String, String> map = (Map<String, Object>) dataSnapshot.getValue(); should have worked. But in any case, I have updated the answer to show how to use GenericTypeIndicator - you can give this one a try - I hope someone can also find this helpful.
  • Thanks, this worked whereas the accepted answer did not.
  • getting this error now com.google.firebase.database.DatabaseException: Expected a Map while deserializing, but got a class java.lang.Stri
  • Worked for me as well. Nice solution!
  • Thank you !! Worked for me.