谷歌在应用程序购买 - 查询库存给出空指针异常

时间:2014-07-24 12:09:37

标签: android in-app-purchase

过去两天我一直在努力实施谷歌inaapp购买但它只是没有用。

Here is my logcat -
07-24 17:23:34.709  11973-11973/com.livebettips D/IabHelper﹕ Starting in-app billing      
setup.
07-24 17:23:34.819  11973-11973/com.livebettips D/IabHelper﹕ Billing service connected.
07-24 17:23:34.819  11973-11973/com.livebettips D/IabHelper﹕ Checking for in-app billing    
3 support.
07-24 17:23:34.869  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:      
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.879  11973-11973/com.livebettips D/IabHelper﹕ In-app billing version 3    
supported for com.livebettips
07-24 17:23:34.889  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:      
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.889  11973-11973/com.livebettips D/IabHelper﹕ Subscriptions AVAILABLE.  
07-24 17:23:34.889  11973-11973/com.livebettips D/LiveBetTips﹕ setting up In-app  
Billing: IabResult: Setup successful. (response: 0:OK)
07-24 17:23:34.889  11973-11973/com.livebettips D/IabHelper﹕ Starting async operation:   
refresh inventory
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Querying owned items, item    
type: inapp
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Package name:   
com.livebettips
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Calling getPurchases with 
continuation token: null
07-24 17:23:34.909  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount: 
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.919  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount: 
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Owned items response: 0
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Continuation token: null
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Querying SKU details.
07-24 17:23:34.939  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.949  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:   
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Querying owned items, item 
type: subs
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Package name:  
com.livebettips
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Calling getPurchases with   
continuation token: null
07-24 17:23:38.079  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.089  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]    
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Owned items response: 0
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Continuation token: null
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Querying SKU details.
07-24 17:23:38.099  11857-11988/? D/Finsky﹕ [28] InAppBillingUtils.getPreferredAccount:     
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.109  11857-11988/? D/Finsky﹕ [28] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:39.279  11973-11989/com.livebettips D/IabHelper﹕ Ending async operation: 
refresh inventory
07-24 17:23:39.279  11973-11973/com.livebettips D/result﹕ IabResult: Inventory refresh 
successful. (response: 0:OK)
07-24 17:23:39.279  11973-11973/com.livebettips W/dalvikvm﹕ threadid=1: thread exiting  
with uncaught exception (group=0x40018578)
07-24 17:23:39.289      160-178/? E/﹕ Dumpstate > /data/log/dumpstate_app_error
07-24 17:23:39.289  11973-11973/com.livebettips E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
        at com.livebettips.activities.InAppBilling$2.onQueryInventoryFinished(InAppBilling.java:94)
        at com.livebettips.util.IabHelper$2$1.run(IabHelper.java:630)
        at android.os.Handler.handleCallback(Handler.java:587)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3687)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
        at dalvik.system.NativeStart.main(Native Method)

这是我的代码 -

   //Google key i got from developer console i split it in 4 parts.key1+key2+key3+key4


    final ArrayList<String> additionalSkuList  = new ArrayList<String>();
    additionalSkuList.add("test2");
    additionalSkuList.add("credit_1");
    additionalSkuList.add("credit_5");

    price = (TextView) findViewById(R.id.tv_inappbilling_price);

    mHelper = new IabHelper(InAppBilling.this,key1+key2+key3+key4);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
            }else{
                Log.d(TAG, "setting up In-app Billing: " + result);

            }
            // Hooray, IAB is fully set up!

            mHelper.queryInventoryAsync(true,additionalSkuList,
                          mQueryFinishedListener);


        }
    });

}

IabHelper.QueryInventoryFinishedListener
        mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory)
    {

        if(mHelper == null){
            Log.d("helper","khatam");
        }

        if (result.isFailure()) {
            // handle error
            return;

        }


        Log.d("result",result.toString());
        if (inventory == null){
           Log.d("inventory",null);
            price.setText("null");
        }else{
            Log.d("inventory",Boolean.toString(inventory.hasDetails("credit_5")));
        }

        String credit_1_Price =
                inventory.getSkuDetails("test2").getSku();    //This is line no 94

        String credit_2_Price =
                inventory.getSkuDetails("credit_5").getPrice();    
        String credit_3_Price =
                inventory.getSkuDetails("credit_1").getPrice();

        price.setText(credit_1_Price+credit_2_Price+credit_3_Price);

        Log.d("Credit 5",credit_2_Price);
        Log.d("Credit 5",credit_3_Price);

        // update the UI
    }
};

我已在开发者控制台上上传了他们处于活动状态的应用内商品。

我读到要在应用程序产品中激活我应该上传apk到alpha阶段我也这样做。

我是否还需要先购买以查看库存商品?我也这样做但失败了。

请heeelllpp!

1 个答案:

答案 0 :(得分:0)

请检查您是否输入了 base64EncodedPublicKey skudetails