java firebase HashMap 未显示为对象字段
我在 firebase 上保存一个对象,它正确显示了除 HashMap 字段之外的所有字段,为什么?我需要保存它,并且需要将其保存为对象字段,不能将其放在其他地方。
MyTrade 类:
HashMap<Float, ArrayList<String>> sells;
public MyTrade() {
this.sells = new HashMap<>();
}
我用来创建对象并将其放在 firebase 上的方法:
databaseReference = FirebaseDatabase.getInstance(URL).getReference().child(coinname.getText().toString()).child("Open Trades");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//set code to retrive data and replace layout
trade = new MyTrade();
dataSnapshot.getRef().child("Trade" + tradekey).setValue(trade);
Intent intent = new Intent(AddTrade.this, Main.class);
startActivity(intent);
finish();
}
@Override
public void onCancelled(DatabaseError databaseError) {
//set code to show an error
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
}
});
当我创建对象 MyTrade 时,它正确初始化哈希图,当我将它放在 firebase 上时它不会给出错误,它只是不显示在上面并且当我尝试获取它时,它告诉我它是空的,因此它给了我空对象引用。
I'm saving an object on firebase, it shows correctly all the field except for the HashMap field, why? I need to save it and I need to save it as object field, can't put it somewhere else.
MyTrade class:
HashMap<Float, ArrayList<String>> sells;
public MyTrade() {
this.sells = new HashMap<>();
}
the method I use to create the object and put it on firebase:
databaseReference = FirebaseDatabase.getInstance(URL).getReference().child(coinname.getText().toString()).child("Open Trades");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//set code to retrive data and replace layout
trade = new MyTrade();
dataSnapshot.getRef().child("Trade" + tradekey).setValue(trade);
Intent intent = new Intent(AddTrade.this, Main.class);
startActivity(intent);
finish();
}
@Override
public void onCancelled(DatabaseError databaseError) {
//set code to show an error
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
}
});
When I create the object MyTrade, it initialize correctly the hashmap, it gives no error when I put it on firebase, it just doesn't show on it and when I try to fetch it it tells me it's null so it gives me null object reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论