首页 > 解决方案 > 无法将 java.lang.String 类型的对象转换为 com.thesis.joinerapp.Model.Joins 类型

问题描述

所以我想根据我从其他活动中获得的值来查询我的 Firebase 数据库。

private String tripID = "";
tripID = getActivity().getIntent().getStringExtra("tripID");
JoinRef = FirebaseDatabase.getInstance().getReference().child("Join").child(tripID);
FirebaseRecyclerOptions<Joins> options = new FirebaseRecyclerOptions.Builder<Joins>().setQuery(JoinRef,Joins.class).build();

数据库结构: 数据库结构

但它显示了一个例外

com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的对象转换为 com.thesis.joinerapp.Model.Joins 类型

标签: androidfirebasefirebase-realtime-database

解决方案


虽然 FirebaseUI 可以为您执行数据查找,但您的数据必须采用非常特定的格式。

如果要显示行程数的子集,索引必须如下所示:

"myTrips": {
    "tripID1": true,
    "tripID2": true
}

您在哪里tripID1tripID2-L您拥有的密钥/Trip

您可以在 FirebaseUI 关于显示索引数据的文档中找到此数据的另一个示例。


推荐阅读