我正在关注此Android-Checkout进行应用内购买。只是感受它是如何工作的。我很清楚它是如何工作的但是我遇到了这个问题。
这是我的Sku Activity类,我收到一个与CheckoutApplication类对应的错误
final Billing billing = CheckoutApplication.get(this).getmBilling();
mCheckout = Checkout.forActivity(this, billing); //Line with error
mCheckout.start();
//Separate class
//This is where the other error is
public static CheckoutApplication get(Activity activity)
{
return (CheckoutApplication) activity.getAcitivty();
}
我不确定导致错误的原因。欢迎任何帮助。感谢
在 com.purchases.inapppurchases.CheckoutApplication.get(CheckoutApplication.java:37) 在 com.purchases.inapppurchases.SkuActivity.onCreate(SkuActivity.java:68)
答案 0 :(得分:1)
return (CheckoutApplication) activity.getAcitivty();
您正在返回一个Activity而不是一个Application,这不能成功投射。尝试返回并转换实际的应用程序:
return (CheckoutApplication) activity.getApplication();
答案 1 :(得分:1)
替换此
public static CheckoutApplication get(Activity activity)
{
return (CheckoutApplication) activity.getAcitivty();
}
与
public static CheckoutApplication get(Activity activity)
{
return (CheckoutApplication) activity.getApplication();
}