leancloud / LeanCloudChatKit-Android

95 stars 33 forks source link

收到离线消息时程序会崩溃 #49

Open ladeng opened 7 years ago

ladeng commented 7 years ago

当应用关闭状态收到推送消息时,此句代码会出现空异常java.lang.NullPointerException挂掉: conversationItemDBHelper.insertData(item.conversationId, item.toJsonString()); 原因是conversationItemDBHelper为null 而conversationItemDBHelper是在chatkit调用open方法成功后才初始化的。

daweibayu commented 7 years ago

可以把具体日志发下么?我看一下具体的错误栈。

ladeng commented 7 years ago

日志如下 cn.leancloud.chatkit.cache.LCIMConversationItemCache.syncToCache(LCIMConversationItemCache.java:255) 2 cn.leancloud.chatkit.cache.LCIMConversationItemCache.syncToCache(LCIMConversationItemCache.java:245) 3 cn.leancloud.chatkit.cache.LCIMConversationItemCache.increaseUnreadCount(LCIMConversationItemCache.java:83) 4 cn.leancloud.chatkit.handler.LCIMConversationHandler.onOfflineMessagesUnread(LCIMConversationHandler.java:37) 5 com.avos.avoscloud.im.v2.AVIMConversationEventHandler.processConversationEvent(AVIMConversationEventHandler.java:105) 6 com.avos.avoscloud.im.v2.AVIMConversationEventHandler.processEvent0(AVIMConversationEventHandler.java:86) 7 com.avos.avoscloud.AVIMEventHandler$1.run(AVIMEventHandler.java:13) 8 android.os.Handler.handleCallback(Handler.java:733) 9 android.os.Handler.dispatchMessage(Handler.java:95) 10 android.os.Looper.loop(Looper.java:136) 11 android.app.ActivityThread.main(ActivityThread.java:5047) 12 java.lang.reflect.Method.invokeNative(Native Method) 13 java.lang.reflect.Method.invoke(Method.java:515) 14 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 15 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 16 dalvik.system.NativeStart.main(Native Method)

这个是我稍作调整的方法和排查的log输出代码: private void syncToCache(LCIMConversationItem item,boolean needUpdateTime) { if (null != item) { if (needUpdateTime) { item.updateTime = System.currentTimeMillis(); } conversationItemMap.put(item.conversationId, item); //test MLog.debug("conversationItemDBHelper:%s ",conversationItemDBHelper==null?"is null":"not null"); MLog.debug("conversationItemDBHelper conversationId:%s",item.conversationId==null?"is null":"not null"); MLog.debug("conversationItemDBHelper toJsonString:%s",item.toJsonString()==null?"is null":"not null");

  conversationItemDBHelper.insertData(item.conversationId, item.toJsonString());
}
//ladeng 更新未读数量
if (onUnReadMessageCountListener!=null){
  onUnReadMessageCountListener.onUnReadMessageCountChange(getAllUnReadCount());
}

} 其中报错在这行: conversationItemDBHelper.insertData(item.conversationId, item.toJsonString()); 收到离线消息并插入数据库的时候,conversationItemDBHelper对象是null的,因为LCIMConversationItemCache的initDB是在chatkit调用open后才初始化的,而我们是在打开应该显示页面后才调用的chatkit的open方法

daweibayu commented 7 years ago

收到,这里确有问题,我修一下。

EggsyChiang commented 7 years ago

@daweibayu 請幫忙修復好後,盡快釋出無問題的新版Chatkit,謝謝