0

This is my code, an attempt to launch an in app purchase when a button is pressed:

purchaseButton.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {

           if(purchased.equals("remove_ads")) {
               Toast.makeText(getApplicationContext(), "You already own the item.",
                       Toast.LENGTH_LONG).show();
           }
           else{

               try{

                   Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(),
                           "remove_ads", "inapp", "key");
                   PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

                   try{
                       startIntentSenderForResult(pendingIntent.getIntentSender(), ///NPE here
                               1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                               Integer.valueOf(0));
                   }
                   catch(IntentSender.SendIntentException ee){
                       Toast.makeText(getApplicationContext(), "Error was: " + ee,
                               Toast.LENGTH_LONG).show();
                   }
                   catch(NullPointerException n){
                       Toast.makeText(getApplicationContext(), "Error was: " + n,
                               Toast.LENGTH_LONG).show();
                   }
               }
               catch (RemoteException e){
                   Toast.makeText(getApplicationContext(), "Error was: " + e,
                           Toast.LENGTH_LONG).show();
                   mHelper.flagEndAsync();

                   mHelper.launchPurchaseFlow(store.this, "remove_ads", 10001,
                           mPurchaseFinishedListener, "key");
               }
           }
       }
   });

and for some reason I get the NPE at the line indicated startIntentSenderForResult... and I don't understand what could cause it. Previously I used this code in another in app purchase exactly as shown except it was a different sku. Could it make a difference since I have 2 identical copies of this code block shown in the same class? Stacktrace doesn't show anything useful either, just the NPE.

ez4nick
  • 9,756
  • 12
  • 37
  • 69
  • http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – user2864740 Jun 21 '14 at 22:02
  • Thanks for the link. However, I understand what a NPE is. What I don't understand is why it happened in this instance. – ez4nick Jun 21 '14 at 22:03
  • 1
    I would hazard a guess that the problem lies just before that with `buyIntentBundle.getParcelable("BUY_INTENT")`. It is perhaps not finding anything with that Key. Try logging some of the details around there or debugging around that point. – indivisible Jun 21 '14 at 22:04

0 Answers0