2017-08-29 5 views
-2

Ich verfolge diese Android-Checkout für In-App-Käufe. Ich habe einfach ein Gefühl dafür, wie es funktioniert. Ich habe eine ziemlich gute Idee, wie alles funktioniert, aber ich bekomme dieses Problem.java.lang.ClassCastException: android.app.Application kann nicht umgewandelt werden

Das ist meine Sku Aktivitätsklasse und ich erhalte eine Fehlermeldung, die mit in der CheckoutApplication Klasse

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

Ich bin nicht sicher, entspricht, was den Fehler verursacht. Jede Hilfe ist willkommen. Dank

bei com.purchases.inapppurchases.CheckoutApplication.get (CheckoutApplication.java:37) bei com.purchases.inapppurchases.SkuActivity.onCreate (SkuActivity.java:68)

Antwort

1

ersetzen diese

public static CheckoutApplication get(Activity activity) 
{ 
    return (CheckoutApplication) activity.getAcitivty(); 
} 

mit

public static CheckoutApplication get(Activity activity) 
{ 
    return (CheckoutApplication) activity.getApplication(); 
} 
+0

Das ist es dank fixiert. –

1
return (CheckoutApplication) activity.getAcitivty(); 

Sie senden eine Aktivität anstelle einer Anwendung, dies kann nicht erfolgreich umgesetzt werden. Versuchen Sie Rückkehr und die tatsächliche Anwendung Gießen statt:

return (CheckoutApplication) activity.getApplication(); 
Verwandte Themen