Swrve / swrve-android-sdk

Swrve Android SDK
http://www.swrve.com
Other
10 stars 18 forks source link

Error when calling IAP methods #273

Closed ignacioola closed 6 years ago

ignacioola commented 6 years ago

Hey guys,

I'm having an error when calling .iap() and .iapPlay() methods. Apparently, it's due to the variable campaignsAndResourcesFlushFrequency not being initialized.

Here's the stacktrace ``` 02-26 13:28:30.810 3192-3233/com.rnswrveexample E/SwrveSDK: Exception thrown in Swrve SDK java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Integer.longValue()' on a null object reference at com.swrve.sdk.SwrveImp.startCampaignsAndResourcesTimer(SwrveImp.java:1111) at com.swrve.sdk.SwrveImp._iap(SwrveImp.java:270) at com.swrve.sdk.SwrveBase._iap(SwrveBase.java:385) at com.swrve.sdk.SwrveBase.iap(SwrveBase.java:1269) at com.swrve.sdk.SwrveBase._iap(SwrveBase.java:381) at com.swrve.sdk.SwrveBase.iap(SwrveBase.java:1260) at io.underscope.RNSwrveModule.iap(RNSwrveModule.java:104) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:154) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:761) ```
Sergio-Mira commented 6 years ago

That variable is setup on initialisation. Are you calling init before using the SDK?

ignacioola commented 6 years ago

Hi Sergio, thanks for your fast response.

I cannot find the method init in the docs here. Could you provide me with a snippet of how should this be called?

Thanks.

Sergio-Mira commented 6 years ago

The init method was present in previous versions of the SDK, what version are you using? In the latest SDK we use Application.ActivityLifecycleCallbacks to call init on 'onCreate' on the first activity. When are you calling the IAP methods?

ignacioola commented 6 years ago

Yeah that was the problem, I am building a React Native native module, so I didn't had access to onCreate from within this module. In order to solve it I had to initialize Swrve SDK from my app.

Thanks for the help.