英文:
Android - Whole data is not getting stored in Firebase Database
问题
以下是翻译好的部分:
我想知道为什么我的全部数据没有存储在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.
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论