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

本小妞迷上赌 提交于 2021-02-08 07:51:10

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/59707015/both-methods-have-same-erasure-yet-neither-overides-the-other-method-clash-er

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!