gpt4 book ai didi

java - Android - 类 java.util.Map 具有通用类型参数,请改用 GenericTypeIndicator

转载 作者:太空狗 更新时间:2023-10-29 13:49:40 24 4
gpt4 key购买 nike

我知道有很多像我这样的问题,但我已经阅读并尝试了所有内容,但仍然无法解决这个问题。我想要实现的是用来自 firebase 的数据填充我的 ListView 。我正在关注 youtube 上的教程,但我添加了一些内容,尤其是时间戳。错误在我的 for 循环中并说:

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

这是我的数据库:

My Database

我的笔记.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;}
}

下面是我的 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) {

}
});

如有任何建议,我们将不胜感激!提前谢谢你。

编辑:好的,我尝试了建议的答案,在我记录 map 后,它在控制台上显示了我的数据。但是,如何将我的 map 迭代到 ListView 中?

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

最佳答案

从您的数据库来看,您似乎应该使用 intlong 类型而不是 map 类型,因为您的时间戳有一个数值

关于java - Android - 类 java.util.Map 具有通用类型参数,请改用 GenericTypeIndicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49767344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com