I receive the follwing error:
java.lang.NullPointerException: Attempt to invoke interface method android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle) on a null object reference
when I'm clicking my button:
skuDetails = billingService.getSkuDetails(3, "com.android.vending.billing", "inapp", querySkus);
All parameters have not null values, but in the same time i got such error.
And full code is below:
connection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
billingService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
billingService = IInAppBillingService.Stub.asInterface(service);
}
};
Intent intent = new Intent("com.android.vending.billing.IInAppBillingService.BIND");
intent.setPackage("com.android.vending.billing");
getBaseContext().bindService(intent, connection, Context.BIND_AUTO_CREATE);
buyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(ITEM_SKU);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Log.e(TAG, "onClick: " + querySkus.getStringArrayList("ITEM_ID_LIST"));
Bundle skuDetails = null;
try {
skuDetails = billingService.getSkuDetails(3,
"com.android.vending.billing",
"inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList = skuDetails
.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
if (sku.equals(ITEM_SKU)) {
System.out.println("price " + price);
Bundle buyIntentBundle = billingService
.getBuyIntent(3, getPackageName(), sku,
"inapp",
base64EncodedPublicKey);
PendingIntent pendingIntent = buyIntentBundle
.getParcelable("BUY_INTENT");
startIntentSenderForResult(
pendingIntent.getIntentSender(), 1001,
new Intent(), Integer.valueOf(0),
Integer.valueOf(0), Integer.valueOf(0));
}
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IntentSender.SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});