Reputation: 3
I am unable to set up in-app billing feature. As written in document, I have done everything up to following code.
package com.fstaer.android;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import com.example.android.trivialdrivesample.util.IabHelper;
import com.example.android.trivialdrivesample.util.IabHelper.QueryInventoryFinishedListener;
import com.example.android.trivialdrivesample.util.IabResult;
import com.example.android.trivialdrivesample.util.Inventory;
import com.example.android.trivialdrivesample.util.Purchase;
public class Getcredits extends Activity{
IabHelper mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.purchase_credits);
String base64EncodedPublicKey = "my public key setup successfully";
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d("getcr", "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
List additionalSkuList = new ArrayList();
additionalSkuList.add("record_pack1");
//additionalSkuList.add(SKU_BANANA);
mHelper.queryInventoryAsync(true, additionalSkuList,
mQueryFinishedListener);
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
}
I am getting error - mQueryFinishedListener cannot be resolved to a variable
If I put QueryInventoryFinishedListener mQueryFinishedListener = null;
it creates java.lang.nullpointerexception
Please anyone help me set up in-app billing
Upvotes: 0
Views: 1692
Reputation: 82543
Add
QueryInventoryFinishedListener
mQueryFinishedListener = new QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
// handle error
return;
}
String applePrice =
inventory.getSkuDetails(SKU_APPLE).getPrice();
String bananaPrice =
inventory.getSkuDetails(SKU_BANANA).getPrice();
// update the UI
}
};
To your class.
If you assign it to null, you will obviously get an NPE. Don't do that.
Upvotes: 1