FireBase RealTimeDb中遇到的问题 常量为空

2022-04-08 00:00:00 专区 静态 是在 常量 回调

个小问题: 静态常量为空

在集成FireBase RealTimeDb,authentication,storage,在添加数据回调以后出现了一个问题,凡是在回调中出现或使用的静态常量都为null,google的回调拿到不在同一个线程,或者从天上来?次遇到静态常量还能为null,debug过程中发现竟然连这个静态常量的类都找不到.....我一脸蒙圈... how should i do???


我尝试了一个笨方法,在Application中初始化一下,结果发现可以使用,已经不空了.


这个问题解决了后,那个使用RealTimeDdataBase的类中 的回调也出现了常量为空的情况,于是我又在构造函数中再次初始化这个常量类


当然了这个String chatList = Constants.ChatList; 完全是没有任何意义的,就是为了防止出现空指针.具体为什么出现这个我也懒得去查原因了.

第二个小问题:获取RealTimeDataBase回调中List集合数据,数据库的结构是这个样子的


返回时接收应该是这个样子的

@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DatabaseReference zzamu = dataSnapshot.getRef();
String callback = zzamu.zzcra().toString();
//会话列表回调
if (callback.contains(Constants.ChatList) && chatListDataChange != null ) {
GenericTypeIndicator<List<ChatListBean>> t = new GenericTypeIndicator<List<ChatListBean>>() {};
List<ChatListBean> list=dataSnapshot.getValue(t);
chatListDataChange.onChatListDataChange(list);
}

源文 出处是在 http://stackoverflow.com/questions/30744224/how-to-retrieve-a-list-object-from-the-firebase-in-android

相关文章