【发布时间】:2018-07-26 12:56:20
【问题描述】:
我查看了其他一些类似问题的答案,但不明白为什么我的问题不起作用。 在我的 firebase 数据库中,我有一个用户列表,其中包含不同的信息。我想从当前的 userId 中检索信息到 recyclerview。
我的代码如下:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference databaseStatus = rootRef.child("other");
String uid = firebaseAuth.getInstance().getCurrentUser().getUid();
databaseStatus.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot ds : snapshot.getChildren()) {
for (DataSnapshot dSnapshot : ds.getChildren()) {
OtherClass otherClass = dSnapshot.getValue(OtherClass.class);
Log.d("Show", otherClass.getOname() == null ? "" : otherClass.getOname());
list.add(otherClass);
}
adapter = new ShowOtherDetails.OtherAdapter(ShowOtherDetails.this, list);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
progressDialog.dismiss();
}
}
这给了我这个错误:
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.mycare.OtherClass
firebase 数据结构如下所示:
请问有人可以帮我吗?
【问题讨论】:
-
你的快照值是给你一个字符串值。
-
移除你的userid下的随机id
-
推送 ID 将来自同一用户的条目存储为唯一的。因为 1 个用户可以向他们的 id 添加多个数据,我希望每个数据都是唯一的,而不是覆盖以前的
标签: java android firebase firebase-realtime-database android-recyclerview