【问题标题】:get value from fireBase for complex object that contains List<string>从 fireBase 获取包含 List<string> 的复杂对象的值
【发布时间】:2019-05-16 13:33:12
【问题描述】:

我有一个包含 List 的对象,当我尝试从 firebase - 数据库中取回值时,我收到一个错误:“com.google.firebase.database.DatabaseException:无法将 java.util.ArrayList 类型的值转换为字符串”

这个对象的setValue没有问题,当前保存的数据。

这是 "warrant" 对象中列表的 set&get 方法:

public class SearchLocation implements Serializable {
private List<String> custodian;

   public void setCustodian(String custodianUid) {
   if(custodian == null)
       custodian = new ArrayList<>();
   custodian.add(custodianUid);
}

public List<String> getCustodian() {
    return custodian;
}

}

这就是我尝试获得淡水河谷的方式:

        DB_Service.getData(evidenceRef, new OnGetDataListener() {
        @Override
       public void onSuccess(DataSnapshot dataSnapshot) {
         searchLocations = new ArrayList<>();

          for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
               SearchLocation searchLocation = snapshot.getValue(SearchLocation.class);
                searchLocation.setUid(snapshot.getKey());
              searchLocations.add(searchLocation);
            }

【问题讨论】:

  • 添加您的 Firebase 数据库结构
  • 添加照片的链接
  • 你解决他的问题了吗?请回复@AleMamo

标签: android list firebase firebase-realtime-database


【解决方案1】:

更新您的setCustodian() 方法。它应该接受 List&lt;String&gt; 而不是 String 。

所以你必须像下面这样更新

 public void setCustodian(List<String> custodian) {
      this.custodian=custodian;
 }

希望它能解决你的问题。

【讨论】:

    猜你喜欢
    • 2021-05-06
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多