0

我无法设置应用内结算功能。正如文档中所写,我已经完成了以下代码的所有工作。

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;
    }
}

我收到错误 - mQueryFinishedListener 无法解析为变量

如果我把QueryInventoryFinishedListener mQueryFinishedListener = null; 它创建 java.lang.nullpointerexception 请任何人帮我设置应用内计费

4

1 回答 1

1

添加

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 
   }
};

到你的班级。

如果你把它赋值为null,你显然会得到一个NPE。不要那样做。

于 2013-03-13T17:17:38.743 回答