question

runar avatar image
runar asked

Nullpointer onPurchaseUpdatesResponse on screen rotate

I'm receiving some crash reports, where my app is crashing when the screen is rotated. Here is the report: [i]java.lang.NullPointerException jM.a(SourceFile:424) jK.onPurchaseUpdatesResponse(SourceFile:175) com.amazon.inapp.purchasing.KiwiPurchaseUpdatesCommandTask$1.run(Unknown Source) android.os.Handler.handleCallback(Handler.java:605) android.os.Handler.dispatchMessage(Handler.java:92) android.os.Looper.loop(Looper.java:137) android.app.ActivityThread.main(ActivityThread.java:4532) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:511) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) dalvik.system.NativeStart.main(Native Method)[/i] The crash happens in com.amazon.inapp.purchasing.KiwiPurchaseUpdatesCommandTask$1 and some obfuscated parts of that, not in my own code. Does anybody have some pointers where I can catch this NullPointerException? I did not see this crash when using the SDK Tester, only when the app went live.
iap
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

runar avatar image
runar answered
I want to add some more information. I used the sample code provided with the SDK and implemented that in my app.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Runar, Thank you for writing to us. This is true that the origin of the stack trace is com.amazon.inapp.purchasing.KiwiPurchaseUpdatesCommandTask$1.run(), but NPE happens in jM.a() which lies in app. So for your clarity, KiwiPurchaseUpdatesCommandTask$1.run() calls onPurchaseUpdatesResponse() of the instance of the subclass (i.e. jM in your app code - obfuscated by you) of BasePurchasingObserver class. Now from jM.a() there are two calls to jM.a(). Your observers onPurchaseUpdatesResponse method looks like, private jM a; public final void onPurchaseUpdatesResponse(PurchaseUpdatesResponse paramPurchaseUpdatesResponse) { ....................... Log.i("ISSDetectotEntitlementsApp", "onPurchaseUpdatesResponse: userId (" + str + ") purchaseUpdatesRequestStatus (" + localPurchaseUpdatesRequestStatus + ")"); [b] if (!this.a.a(str))[/b] { Log.i("ISSDetectotEntitlementsApp", "onPurchaseUpdatesResponse: userId (" + str + ") in response is NOT the same as current user!"); return; } switch (c()[localPurchaseUpdatesRequestStatus.ordinal()]) { default: return; case 1: ........................ if (paramPurchaseUpdatesResponse.isMore()) { .................... } [b] this.a.a(localOffset);[/b] return; ......................... } Can you take a look at your un-obfuscated code and fix the issue in the app code and resubmit to us? Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

runar avatar image
runar answered
Thanks, Funny, I used the proguard gui to de-obfuscate, but it did not translate these two lines back. That's why I thought it was not in my code. I checked the code. It looks like the response (public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse response) ) can be SUCCESSFUL and the userId can be null. This happens when the device is rotated. I'll put some null checks in to it.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.