Got a nullpointer exception with IAP on android device

Got a nullpointer exception with IAP on android device


I just got 2 android vital reports for a null exception. Anyone have a clue what I could do different? This seems to be happening on the init. It is obviously not happening all the time, just randomly. Probably less than 1% startup.

I have the IAP on cocos2d-x 3.17

Here is the trace:

java.lang.NullPointerException :

at (

at com.sdkbox.plugin.SDKBoxIABBillingClient.onSkuDetailsResponse (

at$2$ (

at android.os.Handler.handleCallback (

at android.os.Handler.dispatchMessage (

at android.os.Looper.loop (

at (

at java.lang.reflect.Method.invokeNative (Native Method)

at java.lang.reflect.Method.invoke (

at$ (

at (

at dalvik.system.NativeStart.main (Native Method)


Thanks for your vital report.


I’ve got another one. Is there any way to prevent this? Is there some checks I have to do on my side to prevent something like this?

Report 1 of 1

java.lang.ArrayIndexOutOfBoundsException :

at java.util.ArrayList.remove (

at com.sdkbox.plugin.SDKBoxIABBillingClient.requestProducts (

at com.sdkbox.plugin.IAPWrapper.nativeOnInitialized (Native Method)

at com.sdkbox.plugin.IAPWrapper.access$000 (

at com.sdkbox.plugin.IAPWrapper$ (

at android.opengl.GLSurfaceView$GLThread.guardedRun (

at android.opengl.GLSurfaceView$ (


how do you use IAP api ?


I do init from the appdelegate: sdkbox::IAP::init();

And then I call sdkbox::IAP::refresh(); whenever someone open the shop page.

That’s about it. It does happen rarely and does not seem to be related to a specific device model or android version. So far I received 3 crash reports in requestproduct and 2 in onskudetailsresponse in 10 days. It did not happen on IOS.


we have a fixed jar for this issue. could you plz help to test it ? (25.3 KB)



Ok thanks. I will take a look. It might take a few days to implement and submit and a few weeks to validate. I will write back here around mid-January (or before if I find something)


I am running into issues that are unrelated to the original issue of this post. Not sure if I need to create a new post but anyway if you have an idea:

I tried to copy the JAR you gave me, but it seems I needed the latest versions of SDKBOX plugins. So I updated them via the SDKbox-GUI and all went well. IOS build fine with the new updated version, however I cannot get the android to build (with the official JARs, not the one you gave me). Regardless what I do I get either compile error or some errors that say Program type already present.

It seems the newer version is using a new place to store the jar:\app\libs. While the previous version used cocos2d\cocos\platform\android\java\libs. So I endup with the old JARs in one place and the new JARs in another place. I tried to removed them from one place, I get compile error as it cannot solve import com.sdkbox.plugin.SDKBox. I tried having them at both places and I get link error:

Error: Program type already present:$BillingBroadcastReceiver

I am kind of stuck at the moment. Regardless of my original crash issues, I just cannot make the newer version of SDKBox plugins to compile on android.

******EDIT *****
From another post, I saw that I now had a depedency on billing:1.0 added in the gradle script. So I removed the JAR of this lib and resolved this issue. I then removed all plugin JARs from one place and kept them at the new directory except sdkbox.jar since I need it in both place to compile it seems… I end up with one new duplicate dependency:

Error: Program type already present: com.sdkbox.adbooster.AdBooster

Seems like I really need to put all in the new directory. I end up with the compile error where my cocos2dxactivity java file cannot resolve import com.sdkbox.plugin.SDKBox


So I was able to make it compile and I tested and everything seems to be working. Had to do multiple modifications

sdkbox.jar is within the folder: cocos2d\cocos\platform\android\java\libs
Other plugin jars are within\app\libs
I replaced the original IAPplugin with yours
changed AppActivity extends from com.sdkbox.plugin.SDKBoxActivity to Cocos2dxActivity
Removed android-support-v4.jar, support-annotations-27.1.1.jar and billing-1.0.jar since they were duplicate.
removed the depedency in the gradle file for

I can’t believe I really needed to do all this. I guess a lot of legacy jars and dependencies. However, the fact that I cannot make it work with the extends sdkboxActivity and only work with the base cocos2dxActivity has me a little worried. However, everything seems to be working fine. Not sure what it does with or without.

I will let you know if I see more crashes.


We are sorry for the inconvenience.

It seems that the way you integrate sdkbox is still old. Of course, this is also caused by us. At the beginning of a certain version, sdkbox recommends:

  1. All third-party files are placed in the user’s development directory, such as /
  2. Restore the cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/ file to the engine default state.
  3. extends from com.sdkbox.plugin.SDKBoxActivity.

The automation of this part of the work sdkbox is not done yet, we will fix this problem as soon as possible.

sorry again.


So far so good on the bug. I just got a new bug though. It happened 5 time in the same minute for 1 user:

#00 pc 0000000000018436 /system/lib/ (strcpy+1)

#01 pc 000000000020f185 /data/app/com.bewgames.survivaladventure-1/lib/arm/ (_ZN9c_Billing23onProductRequestSuccessERKNSt6__ndk16vectorIN6sdkbox7ProductENS0_9allocatorIS3_EEEE+356)

#02 pc 00000000002148ef /data/app/com.bewgames.survivaladventure-1/lib/arm/ (ZN6sdkbox17IAPWrapperEnabled22onProductRequestResultENS_18ProductRequestCodeEPKcS3+158)

#03 pc 0000000000212005 /data/app/com.bewgames.survivaladventure-1/lib/arm/ (Java_com_sdkbox_plugin_IAPWrapper_nativeOnRequestResult+100)

#04 pc 00000000006ca55b /data/app/com.bewgames.survivaladventure-1/oat/arm/base.odex


Thanks your crash detail. I’ll fix it ASAP.


onProductRequestSuccess is a iap listener event, this is implement by you, can you check your code?


Ok thanks, I just took a look and the only possibility I see is that I received a title without parenthesis. On android, for god knows why, all the titles I receive contains a parenthesis. So instead of getting

75 full heal potions

I receive

75 full heal potions (full_heal_potion_1)

So I remove the parenthesis portion before displaying it. So I guess the title I received had something different. I can certainly prevent the crash, but it would be good to know why I received something different.


title is get from SkuDetails.

i tried with our sample, get title

Bag of coins (IAP Test)

this seem like app name.