我使用ArrayList
在Firebase
上存储数据。它存储为HashMap
,其键值从0开始,其值存储为字符串。
数据库如下:
我正在使用POJO
来存储和检索数据。
我的POJO
定义如下:
@JsonIgnoreProperties(ignoreUnknown = true)
public class POJO_MemoriesRVDisplay {
String mem_name;
String mem_place_street_address;
HashMap<Object,Object> images;
public POJO_MemoriesRVDisplay() {
}
public HashMap<Object, Object> getImages() {
return images;
}
public void setImages(HashMap<Object, Object> images) {
this.images = images;
}
public POJO_MemoriesRVDisplay(String mem_name, String mem_place_street_address, HashMap<Object, Object> images) {
this.mem_name = mem_name;
this.mem_place_street_address = mem_place_street_address;
this.images = images;
}
public String getMem_name() {
return mem_name;
}
public void setMem_name(String mem_name) {
this.mem_name = mem_name;
}
public String getMem_place_street_address() {
return mem_place_street_address;
}
public void setMem_place_street_address(String mem_place_street_address) {
this.mem_place_street_address = mem_place_street_address;
}
}
当我运行此代码时,出现错误,例如:
Failed to bounce to type
如何正确声明POJO
。我已经尝试了几个帖子,但无法帮助它。尝试将图像声明更改为字符串,仍然无法正常工作。请帮忙!
答案 0 :(得分:1)
问题出在Hashmap宣言中。最初将其声明为
Hasmap<Object, Object> images;
在POJO中无效,但经过数小时的试验和错误后,我删除了POJO并重新启动了系统。当我重新创建POJO文件时,我将Hashmap声明为:
Hashmap images;
答案 1 :(得分:0)
尝试使用此解决方案:
//First create your object
POJO_MemoriesRVDisplay pojo = new POJO_MemoriesRVDisplay("School", "12345", Your hashmap);
//Create your reference where you want to store your data
private DatabaseReference root = FirebaseDatabase.getInstance().getReference();
//Save your data
root.push().setValue(pojo);