问题
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