0

I have the code below (app live, and I got a crash reported at the line with mService.consumePurchase):

Thread trd = new Thread(new Runnable()
{
      @Override
      public void run()
      {
          try
          {
                int response = mService.consumePurchase(3, getPackageName(), sku.mToken);
                if (response == 0)
                {
                    System.out.println("onActivityResult consume ok");
                    purchasesOK.add(sku.mSku);
                }
                else
                {
                    System.out.println("onActivityResult consume failed");
                    purchasesFail.add(sku.mSku);
                    runOnUiThread(new Runnable()
                    {
                         public void run() 
                         {
                            alert("Store Problems!", "There were problems consuming the product, please use RESTORE button.");
                         }
                    });
                }
          } catch (RemoteException e) {
              purchasesFail.add(sku.mSku);
                System.out.println("onActivityResult consume crashed");
                runOnUiThread(new Runnable()
                {
                     public void run() 
                     {
                     alert("Store Problems!", "There were problems consuming the product, please use RESTORE button.");
                     }
                });
            }
     }
});
trd.start();

here is the crash report:

java.lang.NullPointerException at com.XXXXX.GGActivity.j_ItemPurchase(GGActivity.java:1309) at com.XXXXX.GGLib.step(Native Method) at com.XXXXX.GGView$Renderer.onDrawFrame(GGView.java:436) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

I thought that try/catch will show the popup error in any case of exception. Any ideas what might caused it ? Or how can I avoid it?

Thanks, /C.

3
  • 4
    You've got a NullPointerException, but you're catching RemoteException... Commented Aug 26, 2014 at 17:10
  • Crap :-) copy paste combined with too few sleep Commented Aug 26, 2014 at 17:12
  • 1
    You're catching the wrong Exception, change your catch to catch a NullPointerException :) Commented Aug 26, 2014 at 17:14

1 Answer 1

1

Add this:

catch(NullPointerException e){
    purchasesFail.add(sku.mSku);
    System.out.println("onActivityResult consume crashed");
    runOnUiThread(new Runnable(){
        public void run(){
            alert("Store Problems!", "There were problems consuming the product, please use RESTORE button.");
        }
    });
}

in order to show the popup message

Sign up to request clarification or add additional context in comments.

1 Comment

Argh, they commented while I was writing my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.