QuickBlox / quickblox-android-sdk-releases

This repository contains binary distributions of Android products released by QuickBlox.
BSD 3-Clause "New" or "Revised" License
31 stars 15 forks source link

NullPointerException when start app, quickblox 3.8.1 #22

Closed tempersitu closed 3 years ago

tempersitu commented 6 years ago

When I start my app, sometimes it will crash and show the log as below:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.quickblox.auth.session.QBSessionParametersSaver.save(com.quickblox.auth.session.QBSessionParameters)' on a null object reference at com.quickblox.auth.session.QBSessionManager.setSessionParameters(Unknown Source:4) at com.quickblox.auth.session.QuerySignIn.doneSuccess(Unknown Source:117) at com.quickblox.auth.session.Query.notifySuccess(Unknown Source:0) at com.quickblox.auth.session.Query$VersionEntityCallback.completedWithResponse(Unknown Source:65) at com.quickblox.auth.session.Query.completedWithResponse(Unknown Source:11) at com.quickblox.core.server.HttpRequestRunnable$1.handleMessage(Unknown Source:46) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

--------- beginning of system

I had no idea what issues cause this problem. The only part I used was here:

fun enableQBPush(enable: Boolean) { QBSettings.getInstance().isEnablePushNotification = enable }

fun loginQb(application: Application, user: SPUser, waitForChatService: Boolean = false, callback: (success: Boolean, jid: String) -> Unit) { enableQBPush(user.notificationSetting?.message ?: false)

    if (user.jid.isNullOrBlank()) {
        QBUsers.signUpSignInTask(transformSPUserToQBUser(user)).performAsync(object : QBEntityCallback<QBUser> {
            override fun onSuccess(qbUser: QBUser?, p1: Bundle?) {
                log("sign up qb use success")

                qbUser?.let {
                    qbUser.password = SPUtils.md5("sparky_${user.id}@spark.com.hk")
                    this@MessageManager.qbUser = qbUser

                    if (waitForChatService) {
                        loginChatService(qbUser, callback)
                    } else {
                        callback(true, qbUser.id.toString())
                        loginChatService(qbUser)
                    }

                    SubscribeService.subscribeToPushes(application, true)
                }
            }

            override fun onError(p0: QBResponseException?) {
                log("sign up use error, reason: ${p0?.message}")
            }

        })

    } else {

        QBUsers.signIn(transformSPUserToQBUser(user)).performAsync(object : QBEntityCallback<QBUser> {
            override fun onSuccess(qbUser: QBUser?, p1: Bundle?) {
                log("login qb use success")

                qbUser?.let {
                    qbUser.password = SPUtils.md5("sparky_${user.id}@spark.com.hk")
                    this@MessageManager.qbUser = qbUser

                    if (waitForChatService) {
                        loginChatService(qbUser, callback)
                    } else {
                        callback(true, it.id.toString())
                        loginChatService(qbUser)
                    }
                    SubscribeService.subscribeToPushes(application, true)
                }
            }

            override fun onError(p0: QBResponseException?) {
                log("login qb use error, reason: ${p0?.message}")
            }

        })
    }
}

fun loginChatService(qbUser: QBUser, callback: ((success: Boolean, jid: String) -> Unit)? = null) { if (QBChatService.getInstance().isLoggedIn) { callback?.invoke(true, qbUser.id.toString()) return } QBChatService.getInstance().login(qbUser, object : QBEntityCallback { override fun onSuccess(p0: Any?, p1: Bundle?) { log("log in chat service success") QBChatService.getInstance().enableCarbons() callback?.invoke(true, qbUser.id.toString()) }

        override fun onError(p0: QBResponseException?) {
            log("log in chat service fail, reason: ${p0?.message}")
            callback?.invoke(false, qbUser.id.toString())
        }

    })
}

I will call loginQb() after login my app and I used 3.8.1 version. Can anyone help me?