Fatal Exception: java.lang.NullPointerException

mbedial

Member
Hi

We are getting so many
"Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void com.flashphoner.fpwcsapi.webrtc.MediaConnection.setMediaConnectionListener(com.flashphoner.fpwcsapi.webrtc.MediaConnectionListener)' on a null object reference"

in our Android users. The sdk used is wcs-android-sdk-1.0.1.35-release. Do you know how to debug this? We are unable to reproduce it. Any idea?

Stack:

com.flashphoner.fpwcsapi.session.Call$1.run (Call.java:173)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:214)
com.flashphoner.fpwcsapi.util.LooperExecutor.run (LooperExecutor.java:44)

Also another typical crash is

Fatal Exception: org.java_websocket.exceptions.WebsocketNotConnectedException

org.java_websocket.WebSocketImpl.send (WebSocketImpl.java:573)
org.java_websocket.WebSocketImpl.send (WebSocketImpl.java:550)
org.java_websocket.client.WebSocketClient.send (WebSocketClient.java:145)
com.flashphoner.fpwcsapi.ws.WebSocketChannelClient$2.run (WebSocketChannelClient.java:116)
android.os.Handler.handleCallback (Handler.java:873)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:201)
com.flashphoner.fpwcsapi.util.LooperExecutor.run (LooperExecutor.java:44)


Thanks in advance
 

mbedial

Member
Thanks Max,

Hi,Still having sometimes this issue with version 1.0.1.77:Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void com.flashphoner.fpwcsapi.webrtc.MediaConnection.setMediaConnectionListener(com.flashphoner.fpwcsapi.webrtc.MediaConnectionListener)' on a null object reference
com.flashphoner.fpwcsapi.session.Call$1.run (Call.java:171)
android.os.Handler.handleCallback (Handler.java:751)
android.os.Looper.loop (Looper.java:154)
com.flashphoner.fpwcsapi.util.LooperExecutor.run (LooperExecutor.java:44)and also other one:Fatal Exception: org.java_websocket.exceptions.WebsocketNotConnectedException
org.java_websocket.WebSocketImpl.send (WebSocketImpl.java:573)
org.java_websocket.WebSocketImpl.send (WebSocketImpl.java:550)
org.java_websocket.client.WebSocketClient.send (WebSocketClient.java:145)
com.flashphoner.fpwcsapi.ws.WebSocketChannelClient$2.run (WebSocketChannelClient.java:120)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Looper.loop (Looper.java:224)
com.flashphoner.fpwcsapi.util.LooperExecutor.run (LooperExecutor.java:44)

BR
 

Max

Administrator
Staff member
Please check if you are using Android SDK 1.0 on Android 5-7 devices only. On Android 8 and higher, use Android SDK 1.1 (latest build 1.1.0.27).
Please also check if network is good enough, this can happen due to Websocket connection interruption.
 
Last edited:

mbedial

Member
Thanks a lot for your quick answer.
Actually although we are only using 1.0.1.77 (otherwise the apk is 20 mb heavier ) , the crash happens in both SDKs and in all android devices, so it seems that it doesn't depend on it.
Regarding the network, I guess that it'll depend on the user access, since we have a good connection in our DC. Anyway, can a potential connection interruption to generate a crash? How could we al least to avoid the crash?

Thanks in advance.
 

Max

Administrator
Staff member
Regarding the network, I guess that it'll depend on the user access, since we have a good connection in our DC. Anyway, can a potential connection interruption to generate a crash? How could we al least to avoid the crash?
You should handle Session.onDisconnection event to check if Websocket connection is interrupted, please see example on GitHub:
Code:
                    /**
                     * Callback functions for session status events are added to make appropriate changes in controls of the interface when connection is established and closed.
                     */
                    session.on(new SessionEvent() {
                        @Override
                        public void onConnected(final Connection connection) {
                            ...
                        }

                        @Override
                        public void onDisconnection(final Connection connection) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    // do the disconnection job and prevent from stream publishing or playback
                                }
                            });
                        }
                    });
 

mbedial

Member
Hi,



Looking at this crash that many of our clients are experiencing with version 1.0.1.77:





"Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void com.flashphoner.fpwcsapi.webrtc.MediaConnection.setMediaConnectionListener(com.flashphoner.fpwcsapi.webrtc.MediaConnectionListener)' on a null object reference"

Stack:

com.flashphoner.fpwcsapi.session.Call$1.run (Call.java:173)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:214)
com.flashphoner.fpwcsapi.util.LooperExecutor.run (LooperExecutor.java:44)



it seems that in Call class at call() method, mediaConnection in line 75 is null: (see atacched files).

1624868348691.png


mediaConnection is get in line 47 of the same method:



MediaConnection mediaConnection = instance.createMediaConnection(….



And following the calls it ends in WebRTCMediaProvider in createMediaconnection

1624868370687.png


Line 101 seems to be the null value we are getting. Do you know why this “this.factory == null” state can be reached?
 

Max

Administrator
Staff member
What example do you use for testing, on what device? What Android version?
Please check if the problem is reproducing in Streaming-min example from 1.0.1.77 archive. Note that Android must be 5-7, in Android 8 and newer you must use 1.1.0.28.
If problem is not reproducing in Streaming-min or other out-of-the-box example, please modify example source code minimally to reproduce the issue, and send using this form.
 

mbedial

Member
No example. Our production code.We use 1.0.1.77 and we have crashes with Android 7.0 Galaxy S6 edge or Android 7.1.2 M6 Note
As we can't reproduce it (only 1% of our clients have it) we wanted to know if you have any idea why this behaviour could appear
Thanks
 

Max

Administrator
Staff member
As we can't reproduce it (only 1% of our clients have it) we wanted to know if you have any idea why this behaviour could appear
Unfortunately, we cannot reproduce this crash in our examples, but we need a stable reproduction to investigate the issue. So the only recommendation is to modify example code until the issue becomes reproducible. Then, send us the code to analyze.
 

mbedial

Member
We are not able to reproduce the issue in a small example :(

Question: Is it possible that sometimes

Flashphoner.init(this)

ends later than

session = Flashphoner.createSession(new SessionOptions(endpoint));
session.connect(connection);

because Flashphoner.init() runs a thread without a callback?

1625467802605.png


So having a race condition, “factory” object is still null and then in connect fails with NullPointer as we said in our last posts?
 

Max

Administrator
Staff member
We raised the ticket WCS-3231.
Please clarify: do you call Flashphoner.createSession directly after Flashphoner.init() without waiting for any user actions like a button click (as all of our examples do)?
In this case, the workaround may be to call init() on application start and then create session after user clicks something.
 

mbedial

Member
Yes, we do Flashphoner.init(this) at the very start of the activity that use wcs, and then without user intervention we do the rest of the things.

init() uses an Activity as argument. Can we call init() with one activity (MainActivity) as parameter and then do the rest of things in other activity?
 

Max

Administrator
Staff member
Yes, we do Flashphoner.init(this) at the very start of the activity that use wcs, and then without user intervention we do the rest of the things.
In this case, you should wait about a second as workaround.
init() uses an Activity as argument. Can we call init() with one activity (MainActivity) as parameter and then do the rest of things in other activity?
No, you can not because audio context will not be initialized correctly in this case. The activity should be the same.
 
Top