【发布时间】:2019-09-12 18:01:57
【问题描述】:
它不仅仅与这些数据有关,错误与 相同 当我将来自其他设备的数据保存到数据库(firebase)中时,应用程序崩溃,其中数据被检索并设置到其他设备的回收视图中
onDataChange 是实时的,当数据更改时会自动调用它
通知类
public class Notifications {
private String Name;
private String Email;
private String Message;
private String Time;
private String Date;
public Notifications() {
}
public Notifications(String Name, String Email, String Message, String Time, String Date) {
this.Name = Name;
this.Email = Email;
this.Message = Message;
this.Time = Time;
this.Date = Date;
}
public String getName() {
return Name;
}
public String getEmail() {
return Email;
}
public String getMessage() {
return Message;
}
public String getTime() {
return Time;
}
public String getDate() {
return Date;
}
}
DatabaseReference userref = FirebaseDatabase.getInstance().getReference().child("Notification");
userref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
notificationList.clear();
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
Notifications notifications = userSnapshot.getValue(Notifications.class);
notificationList.add(notifications);
}
Collections.reverse(notificationList);
mAdapter = new Adapter_Notification(notificationList);
mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
mRecyclerView.setAdapter(mAdapter);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
显示此错误
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Boolean to type com.example.simpleapplocker.Notifications
排队
notificationList.add(notifications);
启动后检索该数据并显示在回收视图中 这意味着数据存在或者可能创建了通知但没有上传其他数据并且可能调用了这个函数??
【问题讨论】:
-
先生首先检查您的通知模型类属性数据类型。并检查您的数据更改响应。它是给你对象还是布尔结果。
-
根据您来自here的请求,我现在要求您将数据库结构添加为JSON文件或至少作为屏幕截图。也请回复@AlexMamo
-
@AlexMamo 感谢您的光临t 检索所有通知
-
@HasnainSabir 我刚刚用图片更新了问题,你可以看看没有布尔值
-
@MuhammadOwaisChaudhary 请同时添加您的
Notifications课程的内容。
标签: android firebase-realtime-database