简体   繁体   中英

'Both methods have same erasure, yet neither overides the other' method clash error in SkuDetailsResponseListener()

I'm attempting to implement the new inapp billing implementation as the trivial drive 2 implementation appears to have dropped support. The following code to create my mSkuDetails map gives me an odd method clash error. It's copied right from the docs except for the Map insertion line.

 List<String> skuList = new ArrayList<> ();
 skuList.add("item1");
 skuList.add("item2");
 SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
 params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
 billingClient.querySkuDetailsAsync(params.build(),
                        new SkuDetailsResponseListener() {
                            @Override
                            public void onSkuDetailsResponse(BillingResult billingResult,
                                                             List<SkuDetails> skuDetailsList) {
                                if (billingResult.getResponseCode() == 
                                    BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
                                    for (SkuDetails skuDetails : skuDetailsList) {
                                        mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);//will use this for purchase calls
                                    }
                                }
                            }
                        });

在此处输入图片说明

在此处输入图片说明

The error messages on this weren't helpful to say the least. However, when I happened to substititute:

com.android.billingclient.api.SkuDetails//add prefix 'com.android.billingclient.api.'

for every instance of 'SkuDetails', weird errors like the ones in this code piece magically cleared up. Also adding the prefix before every instance of 'Purchase':

com.android.billingclient.api.Purchase//also add prefix before Purchase

fixed other similar errors.

Here is the working code with two substitutions:

List<String> skuList = new ArrayList<> ();
skuList.add("item1");
skuList.add("item2");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
billingClient.querySkuDetailsAsync(params.build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(BillingResult billingResult,
                                                         List<com.android.billingclient.api.SkuDetails> skuDetailsList) {
                            if (billingResult.getResponseCode() == 
                                BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
                                for (com.android.billingclient.api.SkuDetails skuDetails : skuDetailsList) {
                                    mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);//will use this for purchase calls
                                }
                            }
                        }
                    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM