gpt4 book ai didi

java.util.ArrayList 无法转换为 com.android.billingclient.api.SkuDetails

转载 作者:行者123 更新时间:2023-12-02 00:57:17 25 4
gpt4 key购买 nike

我正在尝试将 Revenuecat 实现到我的应用程序中。当我尝试购买时出现此错误:

java.util.ArrayList cannot be cast to com.android.billingclient.api.SkuDetails

在此行中:Purchases.getSharedInstance().purchaseProduct(this, (SkuDetails) skuList, new MakePurchaseListener() {

我试图只购买一种产品。谁能帮我解决这个问题?他们的 sdk 引用是 Kotlin 中的。我请求帮助他们没有帮助。

这是代码:

Show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

// relativeLayout.setVisibility(View.VISIBLE);
List<String> skuList = new ArrayList<>();
skuList.add(ITEM_S);


Purchases.getSharedInstance().getNonSubscriptionSkus(skuList, new GetSkusResponseListener() {
@Override
public void onReceived(@NonNull List<SkuDetails> skus) {
makepurchase(skus);


}

@Override
public void onError(@NonNull PurchasesError error) {

}
});






}

});




private void makepurchase(List<SkuDetails> skuList){

Purchases.getSharedInstance().purchaseProduct(this, (SkuDetails) skuList, new MakePurchaseListener() {
@Override
public void onCompleted(@NonNull Purchase purchase, @NonNull PurchaserInfo purchaserInfo) {


Toast.makeText(UserInformation.this,"Purchase complete",Toast.LENGTH_LONG).show();
}

@Override
public void onError(@NonNull PurchasesError error, boolean userCancelled) {

}
});
}

最佳答案

首先,在onReceived中你正在路过List<SkuDetails> skuList到期望 List<String> 的方法- 应该是:

private void makepurchase(List<SkuDetails> skuList) {
}

然后,根据您的上下文,您应该迭代 skuList 并单独购买每个项目,或者修改 Purchases.getSharedInstance().purchaseProduct 的签名与 List<SkuDetails> 一起工作

更新:迭代skuList单独购买每个 skuItem。

负面影响:尽可能多的消息Purchase complete作为 skuList 的大小

  private void makepurchase(List<SkuDetails> skuList) {
for (SkuDetails skuItem : skuList) {
Purchases.getSharedInstance()
.purchaseProduct(this, skuItem, new MakePurchaseListener() {
@Override
public void onCompleted(
@NonNull Purchase purchase, @NonNull PurchaserInfo purchaserInfo) {

Toast.makeText(UserInformation.this, "Purchase complete", Toast.LENGTH_LONG).show();
}

@Override
public void onError(@NonNull PurchasesError error, boolean userCancelled) {}
});
}
}

关于java.util.ArrayList 无法转换为 com.android.billingclient.api.SkuDetails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61189614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com