java - 更新到 Firebase 数据库时出错
问题描述
我在尝试更新到 Firebase 实时数据库时遇到问题。我收到错误“com.google.firebase.database.DatabaseException: Serializing Arrays is not supported, please use Lists instead
我认为这可能意味着我需要使用另一种方式来更新数据,因为我使用的是 recyclerView 而不是 listView,但现在我有了:
public void update_button(){
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
snapshot.getRef().child("title").setValue(postTitleEdit.getText());
snapshot.getRef().child("desc").setValue(postTextEdit.getText());
Toast.makeText(CowDet.this, "updated", Toast.LENGTH_LONG).show();
CowDet.this.finish();
}
我用来向 Firebase 添加数据的方式是:
mDatabaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
Blog blog = snapshot.getValue(Blog.class);
blogList.add(blog);
blogRecyclerAdapter = new BlogRecyclerAdapter(PostListActivity.this, blogList);
recyclerView.setAdapter(blogRecyclerAdapter);
blogRecyclerAdapter.notifyDataSetChanged();
}
有人可以帮我更新数据吗?我有点卡在这里。
这是我的博客课程:
public class Blog {
public String title;
public String desc;
public String image;
public String timestamp;
public String userid;
public Blog() {
}
public Blog(String title, String desc, String image, String timestamp, String userid, String milkQty, String note) {
this.title = title;
this.desc = desc;
this.image = image;
this.timestamp = timestamp;
this.userid = userid;
}
public Blog(String title, String desc) {
this.title = title;
this.desc = desc;
this.image = image;
this.timestamp = timestamp;
this.userid = userid;
}
public Blog(String toString) {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
}
新的更新按钮
public void update_button(){
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
databaseReference.child("Mblog").child("title").setValue(postTitleEdit);
Toast.makeText(CowDet.this, "updated", Toast.LENGTH_LONG).show();
CowDet.this.finish();
}
新错误:com.google.firebase.database.DatabaseException:发现名称冲突的 getter:getText 我在线收到此错误databaseReference.child("Mblog").child("title").setValue(postTitleEdit);
解决方案
错误消息非常明确。您的Blog
类似乎包含一个数组(带有[]
),Firebase 的序列化程序不支持该数组。你应该使用一个List
类来达到同样的目的。
如果您很难完成这项工作,请编辑您的问题以包含Blog
课程。
推荐阅读
- python - Numpy:在各种索引处将任意数量的零插入矩阵行
- python - 试图提示目录选择菜单
- excel - 如何在 oracle 中使用 YEARFRAC
- reactjs - 将 offsetLimitPagination 与过滤 Apollo Graphql 相结合
- c# - 运动取决于帧速率。我怎样才能让它独立于帧速率
- reactjs - 警告:签名和功能的功能可能无法正常运行,因为其权利使用占位符团队 ID
- javascript - jquery关于表单计算最大值而不提交
- python - 使用 selenium 和 python 进行 YouTube 自动化,从搜索的视频中选择的问题
- python - 如何使用 Spyder 和 Python 2.7 安装 conda 环境?
- java - 在春季批处理中调用 Joblauncher.run 时获取空指针