5

I know there's a lot of similar questions like mine, but I've read and tried everything but still unable to solve this issue. What I am trying to achieve is to populate my listview with the data from the firebase. Im following a tutorial on youtube but Ive added some stuff, timestamp in particular. The error is in my for loop and says :

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

This is my database looks like :

My Database

My Notes.java

    public class Notes {
String noteId;
String noteCategory;
String note;
String rating;
public Map timeStamp;

public Notes(){

}

public Notes(String noteId, String noteCategory, String note, String rating, Map timeStamp) {
    this.noteId = noteId;
    this.noteCategory = noteCategory;
    this.note = note;
    this.rating = rating;
    this.timeStamp = timeStamp;
}


public String getNoteId() {
    return noteId;
}

public String getNoteCategory() {
    return noteCategory;
}

public String getNote() {
    return note;
}

public String getRating() {
    return rating;
}

public Map<String,String> getTimeStamp() { return timeStamp;}
}

And below is my NoteList.java

@Override
protected void onStart() {
    super.onStart();
    databaseNotes.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            notesList.clear();
            for(DataSnapshot noteSnapshot : dataSnapshot.getChildren()){
                Notes notes = noteSnapshot.getValue(Notes.class);
                notesList.add(notes);

            }

            NoteList adapter = new NoteList(MyNotes.this, notesList);
            listViewNotes.setAdapter(adapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

Any advice would be greatly appreciated! Thank you in advance.

EDIT : Okay, Ive tried the suggested answer, and after I logged the map it shows my data on the console. However, how do I iterate my map into the listview ?

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

just change it to long?
I did try change to everything from Map<String,String> to long. But it shows another error
this error com.google.firebase.database.DatabaseException: Expected a Map while deserializing, but got a class java.lang.Long
Have you changed all the references inside the class and used Notes notes = noteSnapshot.getValue(Notes.class);?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.