Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
at com.singular.flutter_sdk.SingularSDK$1$1.run(SingularSDK.java:240)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8068)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Observered in sdk version - 1.0.8
Potential Cause
A Runnable is being posted onto the UIThreadHandler when link is resolved. This could be unnecessary if the SingularLinkHandler.onResolved(linkParams) is invoked in the main thread and could be the root cause.
uiThreadHandler.post(new Runnable() {
@Override
public void run() {
channel.invokeMethod("singularLinksHandlerName",linkParams); // NULL POINTER HERE!!! Due to NULL `channel`
}
});
Potential Fix
If SingularLinkHandler.onResolved(linkParams) is expected to be only called in main thread and only after the flutter engine is attached, then we can just remove the uiThreadHandler.post() and directly invoke the method on the channel
If the link can be resolved from a background thread,
Then we'll need to do two things:
Check if the channel is not null before invoking channel.invokeMethod("singularLinksHandlerName",linkParams)
If the channel is null, then queue this operation up and wait until the flutter engine is attached to invoke pending operations
Stacktrace
Observered in sdk version -
1.0.8
Potential Cause
A
Runnable
is being posted onto the UIThreadHandler when link is resolved. This could be unnecessary if theSingularLinkHandler.onResolved(linkParams)
is invoked in the main thread and could be the root cause.Potential Fix
If
SingularLinkHandler.onResolved(linkParams)
is expected to be only called in main thread and only after the flutter engine is attached, then we can just remove theuiThreadHandler.post()
and directly invoke the method on thechannel
If the link can be resolved from a background thread, Then we'll need to do two things:
channel
is not null before invokingchannel.invokeMethod("singularLinksHandlerName",linkParams)
null
, then queue this operation up and wait until the flutter engine is attached to invoke pending operations