title: How to call getpurchase method in inapp billing app android?
body: <p>I have implemented in app billing activity in my app. its working fine. but to make purchase buttons invisible.i have used the below code , but it is not working.can anybody help on this.</p>
  
  <pre><code> public class MainActivity extends BlundellActivity implements MainMenu {
  
  public Button topicsbutton;
  public Button mediabutton;
  public Button purchasetopicsbutton;
  public Button purchasemediabutton;
  
  
  
  @SuppressWarnings("null")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      IInAppBillingService mService = null;
  
  
          Bundle ownedItems = null;
          try {
              ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
          } catch (RemoteException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      int response = ownedItems.getInt("RESPONSE_CODE");
      if (response == 0) {
         ArrayList&lt;?&gt; ownedSkus = 
            ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
       ArrayList&lt;?&gt; purchaseDataList = 
           ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
  
  
         for (int i = 0; i &lt; purchaseDataList.size(); ++i) {
  
            Object sku = ownedSkus.get(i);
  
            if (sku == Items.SKU1) {
              purchasetopicsbutton.setVisibility(View.INVISIBLE);
                return;
            }
  
            else if (sku == Items.SKU2) {
                  purchasemediabutton.setVisibility(View.INVISIBLE);
                  return;
              }
         } 
  
  
      }
  
  
      setContentView(R.layout.activity_main);
  
      topicsbutton = (Button) findViewById(R.id.button1a);
      mediabutton = (Button) findViewById(R.id.button2a);
      purchasetopicsbutton = (Button) findViewById(R.id.button1);
      purchasemediabutton = (Button) findViewById(R.id.button2);
  }
  
  @Override
  public void onTopicsPurchaseItemClick(View v) {
      navigate().toPurchaseTopicsActivityForResult();
  }
  
  @Override
  public void onMediaPurchaseItemClick(View v) {
      navigate().toPurchaseMediaActivityForResult();
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (Navigator.REQUEST_TOPICS_PURCHASE == requestCode) {
          if (RESULT_OK == resultCode) {
              dealWithSuccessfulTopicsPurchase();
          } else {
              dealWithFailedTopicsPurchase();
          }
      }
  
      else if (Navigator.REQUEST_MEDIA_PURCHASE == requestCode) {
          if (RESULT_OK == resultCode) {
              dealWithSuccessfulMediaPurchase();
          } else {
              dealWithFailedMediaPurchase();
          }
      }
  }
  
  public void dealWithSuccessfulTopicsPurchase() {
      Log.d("Topics purchased");
      popToast("Topics purchased");
      topicsbutton.setVisibility(View.VISIBLE);
      purchasetopicsbutton.setVisibility(View.INVISIBLE);
  
  }
  
  private void dealWithSuccessfulMediaPurchase() {
      Log.d("Media purchased");
      popToast("Media purchased");
      mediabutton.setVisibility(View.VISIBLE);
      purchasemediabutton.setVisibility(View.INVISIBLE);
  
  }
  
  private void dealWithFailedTopicsPurchase() {
      Log.d("Topics purchase failed");
      popToast("Failed to purchase Topics");
  }
  
  private void dealWithFailedMediaPurchase() {
      Log.d("Media purchase failed");
      popToast("Failed to purchase Media");
  }
  
  public void TopicsOpen(View v) {
      navigate().toTopicsopen();
  }
  
  public void MediaOpen(View v) {
      navigate().toMediaopen();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting error in logcat as</p>
  
  <pre><code>06-28 16:50:25.497: E/AndroidRuntime(10522): FATAL EXCEPTION: main
  06-28 16:50:25.497: E/AndroidRuntime(10522): java.lang.RuntimeException: Unable to   start activity ComponentInfo{com.company.firstapp/com.company.firstapp.MainActivity}:   java.lang.NullPointerException
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.os.Looper.loop(Looper.java:137)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread.main(ActivityThread.java:5041)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at java.lang.reflect.Method.invoke(Method.java:511)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at dalvik.system.NativeStart.main(Native Method)
  06-28 16:50:25.497: E/AndroidRuntime(10522): Caused by: java.lang.NullPointerException
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at com.company.firstapp.MainActivity.onCreate(MainActivity.java:75)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.Activity.performCreate(Activity.java:5104)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  06-28 16:50:25.497: E/AndroidRuntime(10522):    ... 11 more
  </code></pre>