stream-chat-android icon indicating copy to clipboard operation
stream-chat-android copied to clipboard

NullPointerException: core.Client.getState()

Open Chikrix opened this issue 6 years ago • 6 comments

I've been getting the following crash randomly whenever I open my app, I started noticing it since I upgraded to v3.5.0. What could be the possible cause and how can I resolve it.

    java.lang.NullPointerException: Attempt to invoke virtual method 'com.getstream.sdk.chat.rest.core.ClientState com.getstream.sdk.chat.rest.core.Client.getState()' on a null object reference
        at com.getstream.sdk.chat.StreamChat$2.onAnyEvent(StreamChat.java:139)
        at com.getstream.sdk.chat.rest.core.ChatEventHandler.dispatchEvent(ChatEventHandler.java:136)
        at com.getstream.sdk.chat.rest.core.Client.onWSEvent(Client.java:648)
        at com.getstream.sdk.chat.rest.EventHandler.handleMessage(EventHandler.java:19)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Chikrix avatar Dec 11 '19 13:12 Chikrix

@Chikrix this happens when the application returns from background or it first start?

andriizhumela avatar Dec 11 '19 14:12 andriizhumela

@andriizhumela mostly when it first starts I think

Chikrix avatar Dec 11 '19 23:12 Chikrix

@Chikrix where you init StreamChat? Maybe you try to use chat without initialization? Please, show your code sample.

andriizhumela avatar Dec 13 '19 12:12 andriizhumela

I downgraded to 3.4.1 to avoid for now, so not seeing this again for now. I am actually seeing this still, it happens occasionally when I just open my app, but not everytime. I am initialising the stream client in my main activity, the log doesn't show me where this error originates from my code, so it makes it difficult to point out the origin from my code, but I'm initialising the stream client in my MainActivity, and other times in my channel list and detail views in case the stream client is destroyed by the system.

Chikrix avatar Dec 17 '19 09:12 Chikrix

I've had to upgrade due to need for changes in the latest update, and I still have this issue.

Chikrix avatar Jan 25 '20 18:01 Chikrix

This is resolved in the 4.x branch

tschellenbach avatar May 16 '20 20:05 tschellenbach