安卓 – 整个数据未能完全存储在Firebase数据库中

huangapple go评论90阅读模式
英文:

Android - Whole data is not getting stored in Firebase Database

问题

以下是翻译好的部分:

我想知道为什么我的全部数据没有存储在Firebase数据库中?这里是我的数据的屏幕截图。

安卓 – 整个数据未能完全存储在Firebase数据库中

这是代码部分:

private void sendMessage() {
    DatabaseReference db = FirebaseDatabase.getInstance().getReference().child("Message");
    String message = editTextMessage.getText().toString();
    if (message.isEmpty()) {
        Toast.makeText(this, "文本不能为空", Toast.LENGTH_LONG).show();
    } else {
        Messages chat = new Messages(user.getUid(), friendId, message, false);
        String chatID = db.push().getKey();
        db.child(chatID).setValue(chat);
        editTextMessage.setText("");
    }
}

我的模型类:

public class Messages {
    String senderId, receiverID, message;
    boolean isSeen;

    public Messages(){}

    public Messages(String senderId, String receiverID, String message, boolean isSeen) {
        this.senderId = senderId;
        this.receiverID = receiverID;
        this.message = message;
        this.isSeen = isSeen;
    }

    public boolean isSeen() {
        return isSeen;
    }

    public void setSeen(boolean seen) {
        isSeen = seen;
    }

    public String getSenderId() {
        return senderId;
    }

    public String getReceiverID() {
        return receiverID;
    }

    public String getMessage() {
        return message;
    }
}

正如您所看到的,我正在存储 chat 对象中的4个值,但实际上只存储了三个。

对于这个问题,您有任何想法或建议吗?

英文:

I wanna know why my whole data is not getting stored in Firebase Database? Here is a Screenshot of of my data.

安卓 – 整个数据未能完全存储在Firebase数据库中

Here is The Code

private void sendMessage() {
        DatabaseReference db = FirebaseDatabase.getInstance().getReference().child("Message");
        String message = editTextMessage.getText().toString();
        if (message.isEmpty()) {
            Toast.makeText(this, "Text cannot be empty", Toast.LENGTH_LONG).show();
        } else {
           Messages chat = new Messages(user.getUid(), friendId, message, false);
           String chatID = db.push().getKey();
           db.child(chatID).setValue(chat);
           editTextMessage.setText("");
        }
    }

My Model Class

public class Messages {
    String senderId, receiverID, message;
    boolean isSeen;

    public Messages(){}

    public Messages(String senderId, String receiverID, String message, boolean isSeen) {
        this.senderId = senderId;
        this.receiverID = receiverID;
        this.message = message;
        this.isSeen = isSeen;
    }

    public boolean isSeen() {
        return isSeen;
    }

    public void setSeen(boolean seen) {
        isSeen = seen;
    }

    public String getSenderId() {
        return senderId;
    }

    public String getReceiverID() {
        return receiverID;
    }

    public String getMessage() {
        return message;
    }

As you can see I am storing 4 values in the chat object but it is only storing three.

Any Idea or Suggestion why this might be...

答案1

得分: 1

几乎可以确定 friendId 为空。实时数据库不会存储任何空值。我们无法看到您在哪里为 friendId 赋值,因此您需要调试一下为什么会出现这种情况。

英文:

It's almost certainly the case that friendId is null. Realtime Database won't store anything for null values. We can't see where you are giving friendId a value, so you'll have to debug why this is.

huangapple
  • 本文由 发表于 2020年7月27日 00:35:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63102893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定